elastic/elasticsearch · error · ParseException
expected EMPTY or
Error message
expected EMPTY or ( but found: {} What it means
Thrown by WellKnownText.nextEmptyOrOpen when the token following a geometry keyword is neither the word EMPTY nor '('. Every geometry in WKT must be followed by either EMPTY (e.g. "POINT EMPTY") or an opening parenthesis for its coordinates.
Solutions
- Add the missing '(' before coordinates or use EMPTY for empty geometries.
- Validate that each geometry keyword is immediately followed by either ' (' or ' EMPTY'.
Example fix
// before: missing open paren after keyword
Geometry g = WellKnownText.fromWKT("POINT 1 2");
// after: include the open paren
Geometry g = WellKnownText.fromWKT("POINT (1 2)");
// or EMPTY for no coordinates
Geometry g = WellKnownText.fromWKT("POINT EMPTY"); Defensive patterns
Strategy: validation
Validate before calling
// Verify each geometry keyword is followed by EMPTY or '('
static void checkBodyOpener(String wkt) {
// for each known keyword, ensure the next non-space token is EMPTY or '('
} Try / catch
try {
Geometry g = WellKnownText.fromWKT(wkt);
} catch (java.text.ParseException e) {
if (e.getMessage().contains("EMPTY or")) {
// missing '(' or EMPTY after keyword
}
throw e;
} Prevention
- Always follow a type keyword with either ' (' or ' EMPTY'.
- Validate WKT structure against the grammar for the geometry type.
When it happens
Trigger: WKT of the form "POINT" followed by something other than EMPTY or '(' — e.g. "POINT 1 2" (missing open paren), "POINT , 1 2", or "POINT)". After reading the type keyword, the parser expects the body opener and finds a different token.
Common situations: Hand-written WKT omitting the opening parenthesis; malformed concatenation of WKT fragments; a copy-paste that dropped the '(' or 'EMPTY'.
Related errors
- coordinate dimensions do not match
- expected ) but found
- expected , but found
- expected
- expected number but found
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/688b5722d6743f61.
Report an issue: GitHub.
Appendix: source
Thrown at libs/geo/src/main/java/org/elasticsearch/geometry/utils/WellKnownText.java:751
try {
token = nextWord(stream);
if (token.equals(Z) || token.equals(M)) {
return true;
}
stream.pushBack();
return false;
} catch (ParseException | IOException e) {
return false;
}
}
static String nextEmptyOrOpen(StreamTokenizer stream) throws IOException, ParseException {
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)) {View on GitHub (pinned to db6a809a66)