apache/flink · error · NumberFormatException

Orphaned minus sign.

Error message

Orphaned minus sign.

What it means

Thrown by IntParser.parseField when the field is a '-' sign with no digits. After consuming the minus and advancing, the parser checks length == 0 or a delimiter at the new position and rejects the sign-only field with NumberFormatException.

Source

Thrown at flink-core/src/main/java/org/apache/flink/types/parser/IntParser.java:137

     * @param delimiter The delimiter that terminates the field.
     * @return The parsed value.
     * @throws NumberFormatException Thrown when the value cannot be parsed because the text
     *     represents not a correct number.
     */
    public static final int parseField(byte[] bytes, int startPos, int length, char delimiter) {
        long val = 0;
        boolean neg = false;

        if (bytes[startPos] == delimiter) {
            throw new NumberFormatException("Empty field.");
        }

        if (bytes[startPos] == '-') {
            neg = true;
            startPos++;
            length--;
            if (length == 0 || bytes[startPos] == delimiter) {
                throw new NumberFormatException("Orphaned minus sign.");
            }
        }

        for (; length > 0; startPos++, length--) {
            if (bytes[startPos] == delimiter) {
                return (int) (neg ? -val : val);
            }
            if (bytes[startPos] < 48 || bytes[startPos] > 57) {
                throw new NumberFormatException("Invalid character.");
            }
            val *= 10;
            val += bytes[startPos] - 48;

            if (val > OVERFLOW_BOUND && (!neg || val > UNDERFLOW_BOUND)) {
                throw new NumberFormatException("Value overflow/underflow");
            }
        }
        return (int) (neg ? -val : val);

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Replace sign-only placeholders in the source with real values or empty fields handled explicitly.
  2. Pre-validate the slice: reject or default when it equals "-" before parsing.
  3. Add data-quality screening for numeric fields matching ^-?\d*$.

Example fix

// before
int v = IntParser.parseField(bytes, start, len, ',');

// after
String field = new String(bytes, start, len, StandardCharsets.UTF_8);
if (field.equals("-")) { throw new IllegalArgumentException("Sign-only int field at " + start); }
int v = IntParser.parseField(bytes, start, len, ',');
Defensive patterns

Strategy: validation

Validate before calling

if (len == 1 && bytes[start] == '-') {
    throw new IllegalArgumentException("Sign-only int field");
}

Try / catch

try {
    int v = IntParser.parseField(bytes, start, len, delim);
} catch (NumberFormatException e) {
    if (e.getMessage().equals("Orphaned minus sign.")) { /* missing value policy */ }
    else throw e;
}

Prevention

When it happens

Trigger: Calling IntParser.parseField where the field slice is exactly "-" between delimiters, e.g. the row "10,-,20" with ',' delimiter.

Common situations: Placeholder '-' for missing values in exported data; truncated negative numbers from partial writes or bad slicing; hand-edited files losing digits.

Related errors


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