apache/flink · error · NumberFormatException

Invalid input: Empty string

Error message

Invalid input: Empty string

What it means

Thrown by BigDecParser.parseField(byte[], int, int, char) when the field length is zero or negative. Before any numeric parsing happens, the parser guards length <= 0 and rejects the field as an empty string with a NumberFormatException. This is the static parseField variant used for delimiter-separated text; it throws rather than returning a null-parsed flag like the FieldParser entry points.

Source

Thrown at flink-core/src/main/java/org/apache/flink/types/parser/BigDecParser.java:109

        return parseField(bytes, startPos, length, (char) 0xffff);
    }

    /**
     * Static utility to parse a field of type BigDecimal from a byte sequence that represents text
     * characters (such as when read from a file stream).
     *
     * @param bytes The bytes containing the text data that should be parsed.
     * @param startPos The offset to start the parsing.
     * @param length The length of the byte sequence (counting from the offset).
     * @param delimiter The delimiter that terminates the field.
     * @return The parsed value.
     * @throws IllegalArgumentException Thrown when the value cannot be parsed because the text
     *     represents not a correct number.
     */
    public static final BigDecimal parseField(
            byte[] bytes, int startPos, int length, char delimiter) {
        if (length <= 0) {
            throw new NumberFormatException("Invalid input: Empty string");
        }
        int i = 0;
        final byte delByte = (byte) delimiter;

        while (i < length && bytes[startPos + i] != delByte) {
            i++;
        }

        if (i > 0
                && (Character.isWhitespace(bytes[startPos])
                        || Character.isWhitespace(bytes[startPos + i - 1]))) {
            throw new NumberFormatException(
                    "There is leading or trailing whitespace in the numeric field.");
        }

        final char[] chars = new char[i];
        for (int j = 0; j < i; j++) {
            final byte b = bytes[startPos + j];

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Fix the source data or the field extraction so numeric columns are never empty (fill defaults or correct delimiter configuration).
  2. Guard the call site: skip or default the field when length <= 0 before invoking parseField.
  3. If empty numeric columns are legitimate in your format, treat them explicitly (e.g. map to null/zero) instead of relying on the parser.

Example fix

// before
BigDecimal v = BigDecParser.parseField(bytes, start, len, '|'); // len may be 0

// after
BigDecimal v = (len <= 0)
    ? null
    : BigDecParser.parseField(bytes, start, len, '|');
Defensive patterns

Strategy: validation

Validate before calling

if (length <= 0) {
    // empty column: skip, default, or raise a domain error with row context
    throw new IllegalArgumentException("Empty BigDecimal column");
}

Try / catch

try {
    BigDecimal v = BigDecParser.parseField(bytes, start, len, delim);
} catch (NumberFormatException e) {
    // route record to side output / dead letter with row context
}

Prevention

When it happens

Trigger: Calling BigDecParser.parseField(bytes, startPos, length, delimiter) with length == 0 — an empty column in a delimited text row — or a negative length from an upstream offset miscalculation.

Common situations: CSV/text input with trailing delimiters or consecutive delimiters creating empty columns; a header/format mismatch where the parsed column positions drift; unit tests feeding empty arrays.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/e911b9c79d4cfe1b. Report an issue: GitHub.