elastic/elasticsearch · error · ParseException
expected number but found: {}
Error message
expected number but found: {} What it means
Thrown by WellKnownText.nextNumber when the StreamTokenizer's next token is not TT_WORD at all (e.g., TT_EOF, TT_EOL, TT_NUMBER, or a punctuation char). Unlike error 586, here there is no word token to even attempt parsing — the token type itself is wrong for a number position.
Source
Thrown at libs/geo/src/main/java/org/elasticsearch/geometry/utils/WellKnownText.java:712
case ',':
return COMMA;
}
throw new ParseException("expected word but found: " + tokenString(stream), stream.lineno());
}
static double nextNumber(StreamTokenizer stream) throws IOException, ParseException {
if (stream.nextToken() == StreamTokenizer.TT_WORD) {
if (stream.sval.equalsIgnoreCase(NAN)) {
return Double.NaN;
} else {
try {
return Double.parseDouble(stream.sval);
} catch (NumberFormatException e) {
throw new ParseException("invalid number found: " + stream.sval, stream.lineno());
}
}
}
throw new ParseException("expected number but found: " + tokenString(stream), stream.lineno());
}
static String tokenString(StreamTokenizer stream) {
return switch (stream.ttype) {
case StreamTokenizer.TT_WORD -> stream.sval;
case StreamTokenizer.TT_EOF -> EOF;
case StreamTokenizer.TT_EOL -> EOL;
case StreamTokenizer.TT_NUMBER -> NUMBER;
default -> "'" + (char) stream.ttype + "'";
};
}
static boolean isNumberNext(StreamTokenizer stream) throws IOException {
final int type = stream.nextToken();
stream.pushBack();
return type == StreamTokenizer.TT_WORD;
}
View on GitHub (pinned to db6a809a66)
Solutions
- Check the WKT string is not truncated and has the expected number of coordinate values per the geometry type.
- Verify comma and parenthesis placement so nextNumber is only called at numeric positions.
- Ensure the StreamTokenizer is configured as WellKnownText expects (numbers not parsed to TT_NUMBER).
Example fix
// before: truncated coordinate tuple (missing second value)
Geometry g = WellKnownText.fromWKT("POINT (1 )");
// after: complete tuple
Geometry g = WellKnownText.fromWKT("POINT (1 2)"); Defensive patterns
Strategy: validation
Validate before calling
// Confirm each coordinate tuple has the expected number of numeric values
static void checkTupleComplete(String wkt, int valuesPerTuple) {
// parse parenthesized groups, split tuples, assert each has valuesPerTuple numbers
} Try / catch
try {
Geometry g = WellKnownText.fromWKT(wkt);
} catch (java.text.ParseException e) {
if (e.getMessage().startsWith("expected number")) {
// likely truncation; report missing numeric value
}
throw e;
} Prevention
- Ensure WKT is not truncated mid-coordinate.
- Verify comma/paren placement so number positions are correct.
- Configure the StreamTokenizer as WellKnownText expects.
When it happens
Trigger: A coordinate position in WKT where the tokenizer hits EOF (truncated after a comma or space), an end-of-line, or a structural character. For example "POINT (1 )" expecting a second number but finding ')' or end-of-string.
Common situations: Truncated WKT cut off mid-coordinate; an extra or missing comma shifting the parser so it reads a delimiter where a number is expected; tokenizer configured to parse numbers (TT_NUMBER) rather than leaving them as words.
Related errors
- When specifying 'Z' or 'M', coordinates must include three v
- maximum nested depth of 1000 exceeded
- coordinate dimensions do not match: {}
- expected word but found: {}
- invalid number found: {}
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/95155b23344c366a.
Report an issue: GitHub.