elastic/elasticsearch · error · ParseException
expected , but found: {}
Error message
expected , but found: {} What it means
Thrown by WellKnownText.nextComma when the token at the current position is not ','. This helper asserts a comma separator, used between elements in multi-component structures.
Source
Thrown at libs/geo/src/main/java/org/elasticsearch/geometry/utils/WellKnownText.java:765
final String next = nextWord(stream);
if (next.equals(EMPTY) || next.equals(LPAREN)) {
return next;
}
throw new ParseException("expected " + EMPTY + " or " + LPAREN + " but found: " + tokenString(stream), stream.lineno());
}
static String nextCloser(StreamTokenizer stream) throws IOException, ParseException {
if (nextWord(stream).equals(RPAREN)) {
return RPAREN;
}
throw new ParseException("expected " + RPAREN + " but found: " + tokenString(stream), stream.lineno());
}
static String nextComma(StreamTokenizer stream) throws IOException, ParseException {
if (nextWord(stream).equals(COMMA)) {
return COMMA;
}
throw new ParseException("expected " + COMMA + " but found: " + tokenString(stream), stream.lineno());
}
static String nextOpener(StreamTokenizer stream) throws IOException, ParseException {
if (nextWord(stream).equals(LPAREN)) {
return LPAREN;
}
throw new ParseException("expected " + LPAREN + " but found: " + tokenString(stream), stream.lineno());
}
static String nextCloserOrComma(StreamTokenizer stream) throws IOException, ParseException {
String token = nextWord(stream);
if (token.equals(COMMA) || token.equals(RPAREN)) {
return token;
}
throw new ParseException("expected " + COMMA + " or " + RPAREN + " but found: " + tokenString(stream), stream.lineno());
}
private static String getWKTName(Geometry geometry) {View on GitHub (pinned to db6a809a66)
Solutions
- Insert the missing ',' separator at the position indicated by stream.lineno().
- Verify the WKT structure matches the grammar for the geometry type (e.g., ring vertices separated by commas, rings separated by commas).
Example fix
// before: missing comma between vertices in a ring
Geometry g = WellKnownText.fromWKT("LINESTRING (0 0 1 1)");
// after: comma-separated vertices
Geometry g = WellKnownText.fromWKT("LINESTRING (0 0, 1 1)"); Defensive patterns
Strategy: try-catch
Try / catch
try {
Geometry g = WellKnownText.fromWKT(wkt);
} catch (java.text.ParseException e) {
if (e.getMessage().contains("expected ,")) {
// missing comma separator at the reported line
}
throw e;
} Prevention
- Insert commas between list elements per the geometry grammar.
- Validate separator placement before parsing.
When it happens
Trigger: WKT where a comma is expected between components but is missing or replaced. This helper is used in specific contexts requiring exactly a comma; if the structure needs comma-or-closer, the parser uses nextCloserOrComma instead.
Common situations: Malformed multi-part WKT where a separator is missing; tokenizer positioned wrong due to a prior error; hand-authored WKT with spaces instead of commas between sub-elements where nextComma is called.
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/75f7aeab8a970c08.
Report an issue: GitHub.