{"record":{"id":"a4ca4e5d218bcf26","repo":"elastic/elasticsearch","slug":"expected-but-found-a4ca4e","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":772,"sourceCode":"    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);\n        if (token.equals(COMMA) || token.equals(RPAREN)) {\n            return token;\n        }\n        throw new ParseException(\"expected \" + COMMA + \" or \" + RPAREN + \" but found: \" + tokenString(stream), stream.lineno());\n    }\n\n    private static String getWKTName(Geometry geometry) {\n        return geometry.visit(new GeometryVisitor<String, RuntimeException>() {\n            @Override\n            public String visit(Circle circle) {\n                return \"CIRCLE\";\n            }\n\n            @Override","sourceCodeStart":754,"sourceCodeEnd":790,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/geo/src/main/java/org/elasticsearch/geometry/utils/WellKnownText.java#L754-L790","documentation":"Thrown by WellKnownText.nextOpener when the token at the current position is not '('. This helper asserts an opening parenthesis, used when descending into a nested sub-structure (e.g., a second-level group in a MultiPolygon or the inner ring group of a Polygon).","triggerScenarios":"WKT where a nested '(' is expected but missing. For example, in a MultiPolygon each polygon is wrapped in its own parens: \"MULTIPOLYGON (((0 0, ...)))\". If an inner '(' is omitted, nextOpener throws.","commonSituations":"Malformed multi-geometry WKT with insufficient nesting levels; hand-authored WKT missing a paren level; conversion bug that flattens nested structures.","solutions":["Add the missing '(' to open the expected sub-group, matching the nesting grammar of the geometry type.","Cross-check against a reference WKT example for the type (e.g., MULTIPOINT, MULTIPOLYGON, GEOMETRYCOLLECTION) to confirm nesting depth."],"exampleFix":"// before: missing inner open paren for polygon in multipolygon\nGeometry g = WellKnownText.fromWKT(\"MULTIPOLYGON ((0 0, 1 0, 1 1, 0 0))\");\n\n// after: correct nesting — polygon ring wrapped in its own parens\nGeometry g = WellKnownText.fromWKT(\"MULTIPOLYGON (((0 0, 1 0, 1 1, 0 0)))\");","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    Geometry g = WellKnownText.fromWKT(wkt);\n} catch (java.text.ParseException e) {\n    if (e.getMessage().contains(\"expected (\")) {\n        // missing nested open paren; check geometry-type nesting grammar\n    }\n    throw e;\n}","preventionTips":["Match nesting depth to the geometry type's grammar (e.g., MULTIPOLYGON uses triple parens).","Cross-check against a reference WKT example for the type."],"tags":["geo","wkt","parsing","elasticsearch","geometry"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}