{"record":{"id":"1e3640df73bc4d50","repo":"elastic/elasticsearch","slug":"invalid-number-found","errorCode":null,"errorMessage":"invalid number found: {}","messagePattern":"invalid number found: (.+?)","errorType":"validation","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"libs/geo/src/main/java/org/elasticsearch/geometry/utils/WellKnownText.java","lineNumber":708,"sourceCode":"            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) {\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();","sourceCodeStart":690,"sourceCodeEnd":726,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/geo/src/main/java/org/elasticsearch/geometry/utils/WellKnownText.java#L690-L726","documentation":"Thrown by WellKnownText.nextNumber when the StreamTokenizer yields a TT_WORD that is neither the literal NAN nor parseable by Double.parseDouble. The tokenizer delivered a word-like token where a numeric coordinate was expected, but the word is not a valid floating-point literal.","triggerScenarios":"A coordinate position in WKT containing a word that is not 'NAN' and not a number, e.g. \"POINT (abc 2)\" or \"POINT (1.x 2)\". The tokenizer treats 'abc' as a word; nextNumber sees TT_WORD, fails Double.parseDouble, and throws.","commonSituations":"Corrupt coordinate data; locale-specific decimal separators (comma vs period) confusing the tokenizer; placeholder tokens like 'NULL' or 'INF' that are not the expected 'NAN'; a field-mapping bug feeding a label into a coordinate slot.","solutions":["Inspect the coordinate token reported (stream.sval) and correct the source data to be a valid double literal or the keyword NAN.","If locale formatting is the cause, normalize decimal separators to '.' upstream.","Validate coordinate fields as numeric before generating WKT."],"exampleFix":"// before: non-numeric coordinate token\nGeometry g = WellKnownText.fromWKT(\"POINT (abc 2)\");\n\n// after: valid numeric literal\nGeometry g = WellKnownText.fromWKT(\"POINT (1.5 2)\");\n// or the special NAN keyword if intended\nGeometry g = WellKnownText.fromWKT(\"POINT (NAN 2)\");","handlingStrategy":"validation","validationCode":"// Pre-check coordinate tokens are numeric or NAN\nstatic boolean isValidCoordinateToken(String tok) {\n    if (tok.equalsIgnoreCase(\"NAN\")) return true;\n    try { Double.parseDouble(tok); return true; }\n    catch (NumberFormatException e) { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n    Geometry g = WellKnownText.fromWKT(wkt);\n} catch (java.text.ParseException e) {\n    if (e.getMessage().startsWith(\"invalid number\")) {\n        // surface the offending token to the user\n    }\n    throw e;\n}","preventionTips":["Validate coordinate fields are numeric (or NAN) before WKT generation.","Normalize locale-specific decimal separators to '.'.","Replace unsupported literals (NULL/INF) with NAN or valid doubles upstream."],"tags":["geo","wkt","parsing","elasticsearch","geometry"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}