apache/flink · error · NumberFormatException

Value overflow/underflow

Error message

Value overflow/underflow

What it means

ShortParser.parseField throws NumberFormatException("Value overflow/underflow") when the accumulated value exceeds what a 16-bit signed short can hold (positive bound 32767, negative bound 32768 magnitude). The parser accumulates into a long and checks against OVERFLOW_BOUND/UNDERFLOW_BOUND after each digit.

Source

Thrown at flink-core/src/main/java/org/apache/flink/types/parser/ShortParser.java:151

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

        for (; length > 0; startPos++, length--) {
            if (bytes[startPos] == delimiter) {
                return (short) (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 (short) (neg ? -val : val);
    }
}

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Change the column type from SMALLINT to INT or BIGINT to match real data ranges
  2. Audit the actual min/max of the column in the source file and align the schema
  3. Check delimiter configuration if merged fields are producing inflated numbers
  4. Clamp or reject out-of-range values in a cleaning step if SHORT is a hard requirement

Example fix

// before
DataTypes.FIELD("port_history_count", DataTypes.SMALLINT())

// after
DataTypes.FIELD("port_history_count", DataTypes.INT())
Defensive patterns

Strategy: validation

Validate before calling

int v = Integer.parseInt(field);
if (v < Short.MIN_VALUE || v > Short.MAX_VALUE) throw new IllegalArgumentException("out of short range: " + v);

Try / catch

catch (NumberFormatException e) { /* widen schema to INT and reprocess */ }

Prevention

When it happens

Trigger: A CSV field assigned SHORT type containing a value outside [-32768, 32767], e.g. '40000' or '-50000'. Note the bound check runs only when a delimiter or end-of-field is processed per digit; values just past the bound trigger on the offending digit.

Common situations: Schema type mismatch: source data actually contains ints/longs (counts, ports near 65535, years+ids) but the column was declared SMALLINT; upstream widened a field without notice; delimited parsing merges two small numbers into one ('12' '345' read as '12345' due to a delimiter bug).

Related errors


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