apache/flink · error · NumberFormatException

Orphaned minus sign.

Error message

Orphaned minus sign.

What it means

Thrown by LongParser.parseField when the field is a lone '-' with no digits. After consuming the sign and advancing the position, the parser sees length == 0 or the 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/LongParser.java:145

     * @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 long 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 neg ? -val : val;
            }
            if (bytes[startPos] < 48 || bytes[startPos] > 57) {
                throw new NumberFormatException("Invalid character.");
            }
            val *= 10;
            val += bytes[startPos] - 48;

            // check for overflow / underflow
            if (val < 0) {
                // this is an overflow/underflow, unless we hit exactly the Long.MIN_VALUE
                if (neg && val == Long.MIN_VALUE) {
                    if (length == 1 || bytes[startPos + 1] == delimiter) {

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Replace sign-only placeholders with real values or explicitly-handled empty fields.
  2. Pre-check the slice for equality with "-" and route such records to error handling.
  3. Screen incoming data for sign-only numeric fields.

Example fix

// before
long v = LongParser.parseField(bytes, start, len, ',');

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

Strategy: validation

Validate before calling

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

Try / catch

try {
    long v = LongParser.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 LongParser.parseField where the field slice between delimiters is exactly "-", e.g. "100,-,200" with ',' delimiter.

Common situations: Missing-value placeholders written as '-'; truncated negatives from partial writes; manual data edits dropping digits after the sign.

Related errors


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