apache/flink · error · NumberFormatException

Orphaned minus sign.

Error message

Orphaned minus sign.

What it means

Thrown by ByteParser.parseField when a field consists of a '-' sign with no digits: after consuming the minus the parser finds length == 0 or the delimiter immediately, i.e. the field text is exactly "-". The sign is consumed and the digit loop would have nothing to read, so it fails fast with NumberFormatException.

Source

Thrown at flink-core/src/main/java/org/apache/flink/types/parser/ByteParser.java:129

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

            if (val > Byte.MAX_VALUE && (!neg || val > -Byte.MIN_VALUE)) {
                throw new NumberFormatException("Value overflow/underflow");
            }
        }
        return (byte) (neg ? -val : val);

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Clean the source data: replace bare '-' placeholders with a real value or an empty field handled explicitly.
  2. Pre-validate the field slice (reject/skip when it equals "-") before calling the parser.
  3. Add a data-quality check on incoming files for sign-only numeric fields.

Example fix

// before
byte v = ByteParser.parseField(bytes, start, len, '|');

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

Strategy: validation

Validate before calling

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

Try / catch

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

Prevention

When it happens

Trigger: Calling ByteParser.parseField where the field slice is exactly "-" — a lone minus sign between delimiters, e.g. "5,-,7" with ',' delimiter.

Common situations: Dirty exports where a negative number lost its digits; placeholder '-' used for missing values in some datasets; partial writes truncating a number right after the sign.

Related errors


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