apache/flink · error · NumberFormatException
Orphaned minus sign.
Error message
Orphaned minus sign.
What it means
ShortParser.parseField throws NumberFormatException("Orphaned minus sign.") when the field starts with '-' but has no digits after it — either the minus is the entire field or it is immediately followed by the delimiter.
Source
Thrown at flink-core/src/main/java/org/apache/flink/types/parser/ShortParser.java:136
* @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 short 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 (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");
}
}
View on GitHub (pinned to 2f3c205e92)
Solutions
- Replace bare '-' placeholders in the source data with a proper value or an explicit null literal
- Configure the CSV connector's null-literal handling if '-' denotes missing
- Validate/clean fields before they reach a SMALLINT-typed parser
Example fix
// before -- CSV: 5,-,7 with schema (a SMALLINT, b SMALLINT, c SMALLINT) // after -- CSV: 5,\N,7 with null-literal configured, or 5,0,7
Defensive patterns
Strategy: validation
Validate before calling
if (field.equals("-") || field.endsWith("-") && field.length() == 1) {
/* placeholder: map to null */
} Try / catch
catch (NumberFormatException e) { log.info("placeholder '-' in short field: {}", rawLine); } Prevention
- Ban bare '-' as a missing-value marker in data contracts
- Validate exported files contain [-]?[0-9]+ only for numeric columns
When it happens
Trigger: A CSV short field containing just '-' (e.g. '5,-,7'), or '-' immediately before the delimiter after the sign-consumption step. The parser advances startPos past '-' and then finds length==0 or the delimiter byte.
Common situations: Data quality issues where '-' is used as a placeholder for missing/unknown values; truncation of negative numbers during export; user-typed placeholders in generated test files.
Related errors
- Empty field.
- Invalid character.
- Value overflow/underflow
- Row too short: {}
- Line could not be parsed: '{}' ParserError {} Expect field
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/efb2f49686d1cff0.
Report an issue: GitHub.