{"record":{"id":"b51fc63a4c8b6926","repo":"github/copilot-sdk","slug":"expected-number-at-position-start","errorCode":null,"errorMessage":"Expected number at position <start>","messagePattern":"Expected number at position <start>","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"java/sdk/src/main/java/com/github/copilot/tool/CopilotToolProcessor.java","lineNumber":1106,"sourceCode":"            }\n            throw new IllegalArgumentException(\"Expected boolean at position \" + pos);\n        }\n\n        private String parseNull() {\n            if (input.startsWith(\"null\", pos)) {\n                pos += 4;\n                return \"(Object) null\";\n            }\n            throw new IllegalArgumentException(\"Expected null at position \" + pos);\n        }\n\n        private String parseNumber() {\n            int start = pos;\n            if (pos < input.length() && input.charAt(pos) == '-') {\n                pos++;\n            }\n            if (pos >= input.length()) {\n                throw new IllegalArgumentException(\"Expected number at position \" + start);\n            }\n            if (input.charAt(pos) == '0') {\n                pos++;\n            } else if (isDigitOneToNine(input.charAt(pos))) {\n                consumeDigits();\n            } else {\n                throw new IllegalArgumentException(\"Expected number at position \" + pos);\n            }\n            if (pos < input.length() && input.charAt(pos) == '.') {\n                pos++;\n                requireDigit(\"fraction\");\n                consumeDigits();\n            }\n            if (pos < input.length() && (input.charAt(pos) == 'e' || input.charAt(pos) == 'E')) {\n                pos++;\n                if (pos < input.length() && (input.charAt(pos) == '+' || input.charAt(pos) == '-')) {\n                    pos++;\n                }","sourceCodeStart":1088,"sourceCodeEnd":1124,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/java/sdk/src/main/java/com/github/copilot/tool/CopilotToolProcessor.java#L1088-L1124","documentation":"parseNumber requires that after an optional leading minus there is at least one digit forming a valid JSON number. If the input ends right after the '-' or the next character is not a digit, this IllegalArgumentException is thrown reporting the start position of the would-be number. Note the reported position is the start of the number, not where parsing stopped.","triggerScenarios":"Parsing JSON with '-' or '-x' where a number is expected, e.g. '{\"n\":-}' or '{\"n\":-abc}'; also truncated payloads ending in '-'.","commonSituations":"Hand-built JSON with an empty numeric value or a placeholder ('-{value}' where the template variable was blank); NaN/Infinity written literally (JSON forbids them) so the parser sees 'N'/'I' after nothing valid; truncated streams.","solutions":["Supply a valid JSON number (integer or decimal) at the reported position — JSON numbers must start with a digit after the optional minus","If the value is genuinely not a number, use null instead of a blank/placeholder","Check templates/interpolation that left a blank where a number should be; JSON forbids NaN/Infinity — omit the field or use null","Validate the full JSON with a standard parser to find all malformed numbers"],"exampleFix":"// before\nString json = \"{\\\"count\\\":-}\"; // empty number\n// after\nString json = \"{\\\"count\\\":0}\"; // or null if absent","handlingStrategy":"validation","validationCode":"java.util.regex.Matcher m = java.util.regex.Pattern.compile(\":\\\\s*-\\\\s*[,}\\\\]]\").matcher(json);\nif (m.find()) {\n    throw new IllegalArgumentException(\"Empty numeric value at index \" + m.start());\n}","typeGuard":null,"tryCatchPattern":"try {\n    String result = CopilotToolProcessor.jsonToMapOfSource(json);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"Expected number\")) {\n        // fill in a valid number or use null at the reported start position\n    }\n}","preventionTips":["Check templates: a blank interpolated variable leaves '-x' or '-' where a number belongs","JSON has no NaN/Infinity — omit the field or use null instead","Ensure numeric fields are never empty strings or lone minus signs","Validate numbers with a reference JSON parser before custom parsing"],"tags":["java","json","parsing","number"],"backgroundTag":"json-parse-error","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}