{"record":{"id":"6cf29da43b3b41a2","repo":"elastic/elasticsearch","slug":"expected-word-but-found","errorCode":null,"errorMessage":"expected word but found: {}","messagePattern":"expected word but found: (.+?)","errorType":"validation","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"libs/geo/src/main/java/org/elasticsearch/geometry/utils/WellKnownText.java","lineNumber":697,"sourceCode":"        return circle;\n    }\n\n    /**\n     * next word in the stream\n     */\n    static String nextWord(StreamTokenizer stream) throws ParseException, IOException {\n        switch (stream.nextToken()) {\n            case StreamTokenizer.TT_WORD:\n                final String word = stream.sval;\n                return word.equalsIgnoreCase(EMPTY) ? EMPTY : word;\n            case '(':\n                return LPAREN;\n            case ')':\n                return RPAREN;\n            case ',':\n                return COMMA;\n        }\n        throw new ParseException(\"expected word but found: \" + tokenString(stream), stream.lineno());\n    }\n\n    static double nextNumber(StreamTokenizer stream) throws IOException, ParseException {\n        if (stream.nextToken() == StreamTokenizer.TT_WORD) {\n            if (stream.sval.equalsIgnoreCase(NAN)) {\n                return Double.NaN;\n            } else {\n                try {\n                    return Double.parseDouble(stream.sval);\n                } catch (NumberFormatException e) {\n                    throw new ParseException(\"invalid number found: \" + stream.sval, stream.lineno());\n                }\n            }\n        }\n        throw new ParseException(\"expected number but found: \" + tokenString(stream), stream.lineno());\n    }\n\n    static String tokenString(StreamTokenizer stream) {","sourceCodeStart":679,"sourceCodeEnd":715,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/geo/src/main/java/org/elasticsearch/geometry/utils/WellKnownText.java#L679-L715","documentation":"Thrown by WellKnownText.nextWord when the StreamTokenizer's next token is not TT_WORD and not one of the structural characters '(', ')', ','. This helper expects a keyword or a delimiter; anything else (EOF, EOL, a number, or an unexpected symbol) is rejected.","triggerScenarios":"Any WKT sub-parse that calls nextWord and encounters EOF (truncated string), a number where a keyword/delimiter is expected, or a stray symbol. For example, after reading a type keyword, nextEmptyOrOpen calls nextWord expecting EMPTY or '(' but hits EOF or a number.","commonSituations":"Truncated WKT string (missing the body); a stray character inserted by copy-paste; a tokenizer left mid-stream after a prior error; encoding issues producing unexpected bytes.","solutions":["Inspect the full WKT string for truncation or stray characters around the position reported by stream.lineno().","Ensure the string is complete: balanced parens, all keywords present.","Re-tokenize from a clean StreamTokenizer if a prior parse failed mid-stream."],"exampleFix":"// before: truncated WKT (keyword with no body)\nGeometry g = WellKnownText.fromWKT(\"POINT\");\n\n// after: complete WKT\nGeometry g = WellKnownText.fromWKT(\"POINT (1 2)\");","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().startsWith(\"expected word\")) {\n        // report the unexpected token and line number to the user\n    }\n    throw e;\n}","preventionTips":["Ensure WKT strings are complete and not truncated.","Remove stray characters before keywords and delimiters.","Use a fresh tokenizer per parse."],"tags":["geo","wkt","parsing","elasticsearch","geometry"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T11:17:21.771Z"}