{"record":{"id":"95155b23344c366a","repo":"elastic/elasticsearch","slug":"expected-number-but-found","errorCode":null,"errorMessage":"expected number but found: {}","messagePattern":"expected number but found: (.+?)","errorType":"validation","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"libs/geo/src/main/java/org/elasticsearch/geometry/utils/WellKnownText.java","lineNumber":712,"sourceCode":"            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) {\n        return switch (stream.ttype) {\n            case StreamTokenizer.TT_WORD -> stream.sval;\n            case StreamTokenizer.TT_EOF -> EOF;\n            case StreamTokenizer.TT_EOL -> EOL;\n            case StreamTokenizer.TT_NUMBER -> NUMBER;\n            default -> \"'\" + (char) stream.ttype + \"'\";\n        };\n    }\n\n    static boolean isNumberNext(StreamTokenizer stream) throws IOException {\n        final int type = stream.nextToken();\n        stream.pushBack();\n        return type == StreamTokenizer.TT_WORD;\n    }\n","sourceCodeStart":694,"sourceCodeEnd":730,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/geo/src/main/java/org/elasticsearch/geometry/utils/WellKnownText.java#L694-L730","documentation":"Thrown by WellKnownText.nextNumber when the StreamTokenizer's next token is not TT_WORD at all (e.g., TT_EOF, TT_EOL, TT_NUMBER, or a punctuation char). Unlike error 586, here there is no word token to even attempt parsing — the token type itself is wrong for a number position.","triggerScenarios":"A coordinate position in WKT where the tokenizer hits EOF (truncated after a comma or space), an end-of-line, or a structural character. For example \"POINT (1 )\" expecting a second number but finding ')' or end-of-string.","commonSituations":"Truncated WKT cut off mid-coordinate; an extra or missing comma shifting the parser so it reads a delimiter where a number is expected; tokenizer configured to parse numbers (TT_NUMBER) rather than leaving them as words.","solutions":["Check the WKT string is not truncated and has the expected number of coordinate values per the geometry type.","Verify comma and parenthesis placement so nextNumber is only called at numeric positions.","Ensure the StreamTokenizer is configured as WellKnownText expects (numbers not parsed to TT_NUMBER)."],"exampleFix":"// before: truncated coordinate tuple (missing second value)\nGeometry g = WellKnownText.fromWKT(\"POINT (1 )\");\n\n// after: complete tuple\nGeometry g = WellKnownText.fromWKT(\"POINT (1 2)\");","handlingStrategy":"validation","validationCode":"// Confirm each coordinate tuple has the expected number of numeric values\nstatic void checkTupleComplete(String wkt, int valuesPerTuple) {\n    // parse parenthesized groups, split tuples, assert each has valuesPerTuple numbers\n}","typeGuard":null,"tryCatchPattern":"try {\n    Geometry g = WellKnownText.fromWKT(wkt);\n} catch (java.text.ParseException e) {\n    if (e.getMessage().startsWith(\"expected number\")) {\n        // likely truncation; report missing numeric value\n    }\n    throw e;\n}","preventionTips":["Ensure WKT is not truncated mid-coordinate.","Verify comma/paren placement so number positions are correct.","Configure the StreamTokenizer as WellKnownText expects."],"tags":["geo","wkt","parsing","elasticsearch","geometry"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}