{"record":{"id":"688b5722d6743f61","repo":"elastic/elasticsearch","slug":"expected-empty-or-but-found","errorCode":null,"errorMessage":"expected EMPTY or ( but found: {}","messagePattern":"expected EMPTY or \\( but found: (.+?)","errorType":"validation","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"libs/geo/src/main/java/org/elasticsearch/geometry/utils/WellKnownText.java","lineNumber":751,"sourceCode":"        try {\n            token = nextWord(stream);\n            if (token.equals(Z) || token.equals(M)) {\n                return true;\n            }\n            stream.pushBack();\n            return false;\n        } catch (ParseException | IOException e) {\n            return false;\n        }\n\n    }\n\n    static String nextEmptyOrOpen(StreamTokenizer stream) throws IOException, ParseException {\n        final String next = nextWord(stream);\n        if (next.equals(EMPTY) || next.equals(LPAREN)) {\n            return next;\n        }\n        throw new ParseException(\"expected \" + EMPTY + \" or \" + LPAREN + \" but found: \" + tokenString(stream), stream.lineno());\n    }\n\n    static String nextCloser(StreamTokenizer stream) throws IOException, ParseException {\n        if (nextWord(stream).equals(RPAREN)) {\n            return RPAREN;\n        }\n        throw new ParseException(\"expected \" + RPAREN + \" but found: \" + tokenString(stream), stream.lineno());\n    }\n\n    static String nextComma(StreamTokenizer stream) throws IOException, ParseException {\n        if (nextWord(stream).equals(COMMA)) {\n            return COMMA;\n        }\n        throw new ParseException(\"expected \" + COMMA + \" but found: \" + tokenString(stream), stream.lineno());\n    }\n\n    static String nextOpener(StreamTokenizer stream) throws IOException, ParseException {\n        if (nextWord(stream).equals(LPAREN)) {","sourceCodeStart":733,"sourceCodeEnd":769,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/geo/src/main/java/org/elasticsearch/geometry/utils/WellKnownText.java#L733-L769","documentation":"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.","triggerScenarios":"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.","commonSituations":"Hand-written WKT omitting the opening parenthesis; malformed concatenation of WKT fragments; a copy-paste that dropped the '(' or 'EMPTY'.","solutions":["Add the missing '(' before coordinates or use EMPTY for empty geometries.","Validate that each geometry keyword is immediately followed by either ' (' or ' EMPTY'."],"exampleFix":"// before: missing open paren after keyword\nGeometry g = WellKnownText.fromWKT(\"POINT 1 2\");\n\n// after: include the open paren\nGeometry g = WellKnownText.fromWKT(\"POINT (1 2)\");\n// or EMPTY for no coordinates\nGeometry g = WellKnownText.fromWKT(\"POINT EMPTY\");","handlingStrategy":"validation","validationCode":"// Verify each geometry keyword is followed by EMPTY or '('\nstatic void checkBodyOpener(String wkt) {\n    // for each known keyword, ensure the next non-space token is EMPTY or '('\n}","typeGuard":null,"tryCatchPattern":"try {\n    Geometry g = WellKnownText.fromWKT(wkt);\n} catch (java.text.ParseException e) {\n    if (e.getMessage().contains(\"EMPTY or\")) {\n        // missing '(' or EMPTY after keyword\n    }\n    throw e;\n}","preventionTips":["Always follow a type keyword with either ' (' or ' EMPTY'.","Validate WKT structure against the grammar for the geometry type."],"tags":["geo","wkt","parsing","elasticsearch","geometry"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}