{"record":{"id":"59494bdb8d99e69d","repo":"json-path/JsonPath","slug":"target-json-value-must-a-number-not-state","errorCode":null,"errorMessage":"Target json value must a number, not \" + state","messagePattern":"Target json value must a number, not \" \\+ state","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/spi/mapper/JakartaMappingProvider.java","lineNumber":482,"sourceCode":"        public String getString() {\r\n            switch (state) {\r\n            case KEY_NAME:\r\n                return ((JsonObjectScope) scope).getKey();\r\n            case VALUE_STRING:\r\n                return ((JsonString) scope.getValue()).getString();\r\n            case VALUE_NUMBER:\r\n                return ((JsonNumber) scope.getValue()).toString();\r\n            default:\r\n                throw new IllegalStateException(\"Parser is not in KEY_NAME, VALUE_STRING, or VALUE_NUMBER state\");\r\n            }\r\n        }\r\n\r\n        @Override\r\n        public boolean isIntegralNumber() {\r\n            if (state == Event.VALUE_NUMBER) {\r\n                return ((JsonNumber) scope.getValue()).isIntegral();\r\n            }\r\n            throw new IllegalStateException(\"Target json value must a number, not \" + state);\r\n        }\r\n\r\n        @Override\r\n        public int getInt() {\r\n            if (state == Event.VALUE_NUMBER) {\r\n                return ((JsonNumber) scope.getValue()).intValue();\r\n            }\r\n            throw new IllegalStateException(\"Target json value must a number, not \" + state);\r\n        }\r\n\r\n        @Override\r\n        public long getLong() {\r\n            if (state == Event.VALUE_NUMBER) {\r\n                return ((JsonNumber) scope.getValue()).longValue();\r\n            }\r\n            throw new IllegalStateException(\"Target json value must a number, not \" + state);\r\n        }\r\n\r","sourceCodeStart":464,"sourceCodeEnd":500,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/spi/mapper/JakartaMappingProvider.java#L464-L500","documentation":"isIntegralNumber() in the JakartaMappingProvider JSON-P adapter only works when the parser's current event is VALUE_NUMBER; otherwise it throws this IllegalStateException. It is a strict precondition check: the method exists so callers can test whether the current number is integral, so calling it when no number is current is a programming error.","triggerScenarios":"Calling isIntegralNumber() while the parser state is not Event.VALUE_NUMBER — e.g. current scope is a string, array, object, boolean, or null value.","commonSituations":"Generic number-handling code that forgets to check the current event before probing numeric properties; iterating mixed-type JSON and applying numeric APIs to non-numeric tokens.","solutions":["Guard with the current Event: only call isIntegralNumber() after next() returned Event.VALUE_NUMBER","Switch on the event and route each token type to its proper accessor before probing numeric traits","If you need to test the type of arbitrary values, inspect the JsonValue value type instead of the parser-state accessors"],"exampleFix":"// before\nboolean integral = parser.isIntegralNumber(); // throws unless on a number\n// after\nif (parser.next() == Event.VALUE_NUMBER) {\n    boolean integral = parser.isIntegralNumber();\n}","handlingStrategy":"type-guard","validationCode":"// guard before probing numeric traits\nif (state == Event.VALUE_NUMBER) { parser.isIntegralNumber(); }","typeGuard":"boolean isNumberToken(Event ev) {\n    return ev == Event.VALUE_NUMBER;\n}","tryCatchPattern":"try {\n    boolean integral = parser.isIntegralNumber();\n} catch (IllegalStateException e) {\n    // current token is not a number; handle non-numeric branch\n}","preventionTips":["Check Event.VALUE_NUMBER before any numeric probe (isIntegralNumber/getInt/getLong/getBigDecimal)","Handle VALUE_STRING tokens for numbers-quoted-as-strings explicitly","Keep event-stream iteration and value extraction in one well-tested loop"],"tags":["json","illegal-state","json-path","number"],"backgroundTag":"type-mismatch","analyzedSha":"62a4c9f0f65ba3f625aa0867d64c528ba72d09ec","analyzedAt":"2026-09-11T11:36:00.448Z","contentChangedAt":"2026-09-11T11:36:00.448Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}