{"record":{"id":"f751034bc189a1aa","repo":"elastic/elasticsearch","slug":"expected-but-found","errorCode":null,"errorMessage":"expected ) but found: {}","messagePattern":"expected \\) but found: (.+?)","errorType":"validation","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"libs/geo/src/main/java/org/elasticsearch/geometry/utils/WellKnownText.java","lineNumber":758,"sourceCode":"        } 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)) {\n            return LPAREN;\n        }\n        throw new ParseException(\"expected \" + LPAREN + \" but found: \" + tokenString(stream), stream.lineno());\n    }\n\n    static String nextCloserOrComma(StreamTokenizer stream) throws IOException, ParseException {\n        String token = nextWord(stream);","sourceCodeStart":740,"sourceCodeEnd":776,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/geo/src/main/java/org/elasticsearch/geometry/utils/WellKnownText.java#L740-L776","documentation":"Thrown by WellKnownText.nextCloser when the token following a coordinate sequence is not ')'. This helper asserts the closing parenthesis that terminates a geometry's parenthesized body.","triggerScenarios":"WKT where a closing ')' is missing or replaced, e.g. \"POINT (1 2,\" (trailing comma then EOF), \"POINT (1 2 3\" (no closer), or \"POINT (1 2]\" (wrong bracket). After reading the last coordinate, nextCloser expects ')' but finds something else.","commonSituations":"Truncated WKT missing the final ')'; wrong bracket type from a non-WKT source; an extra token after the last coordinate.","solutions":["Ensure every '(' has a matching ')' and no stray tokens sit between the last coordinate and the closer.","Validate paren balance in the WKT string before parsing."],"exampleFix":"// before: missing closing paren\nGeometry g = WellKnownText.fromWKT(\"POINT (1 2\");\n\n// after: balanced parens\nGeometry g = WellKnownText.fromWKT(\"POINT (1 2)\");","handlingStrategy":"validation","validationCode":"// Verify parenthesis balance\nstatic void checkParenBalance(String wkt) {\n    int depth = 0;\n    for (int i = 0; i < wkt.length(); i++) {\n        char c = wkt.charAt(i);\n        if (c == '(') depth++;\n        else if (c == ')') depth--;\n        if (depth < 0) throw new IllegalArgumentException(\"unbalanced ')' in WKT\");\n    }\n    if (depth != 0) throw new IllegalArgumentException(\"unbalanced '(' in WKT\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    Geometry g = WellKnownText.fromWKT(wkt);\n} catch (java.text.ParseException e) {\n    if (e.getMessage().contains(\"expected )\")) {\n        // missing closing paren\n    }\n    throw e;\n}","preventionTips":["Balance all parentheses in WKT strings.","Avoid stray tokens after the last coordinate."],"tags":["geo","wkt","parsing","elasticsearch","geometry"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}