{"record":{"id":"6b80cc68d4923709","repo":"json-path/JsonPath","slug":"parser-is-not-in-key-name-value-string-or-value","errorCode":null,"errorMessage":"Parser is not in KEY_NAME, VALUE_STRING, or VALUE_NUMBER state","messagePattern":"Parser is not in KEY_NAME, VALUE_STRING, or VALUE_NUMBER state","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/spi/mapper/JakartaMappingProvider.java","lineNumber":473,"sourceCode":"                            state = Event.END_OBJECT;\r\n                        }\r\n                    }\r\n                }\r\n            }\r\n            return state;\r\n        }\r\n\r\n        @Override\r\n        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","sourceCodeStart":455,"sourceCodeEnd":491,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/spi/mapper/JakartaMappingProvider.java#L455-L491","documentation":"JakartaMappingProvider's JSON-P parser adapter exposes getString() only when the underlying parser is positioned on a key name, a string value, or a number value (which is returned as its string form). If the parser sits on any other event (START_ARRAY, START_OBJECT, VALUE_TRUE, VALUE_FALSE, VALUE_NULL, etc.), the adapter throws this IllegalStateException instead of returning a meaningless value. It indicates the caller pulled a string at the wrong point in the JSON event stream.","triggerScenarios":"Calling getString() on the adapter returned by JakartaMappingProvider when the current parser state (Event) is not KEY_NAME, VALUE_STRING, or VALUE_NUMBER — e.g. calling getString() right after next() returned START_ARRAY or VALUE_NULL.","commonSituations":"Custom mapping/provider code iterating the JSON-P event stream out of order; a custom JsonProvider integration misusing the adapter; library version upgrades where parser event sequencing changed.","solutions":["Check the current event with hasNext()/next() and only call getString() when the event is KEY_NAME, VALUE_STRING, or VALUE_NUMBER","Use the accessor matching the current state (getInt/getLong/getBigDecimal for VALUE_NUMBER, isIntegralNumber for numeric checks)","If this happens inside custom mapping logic, inspect what Configuration.mappingConfiguration() provider is set and ensure code paths match the adapter's streaming contract"],"exampleFix":"// before\nString s = parser.getString(); // may throw if event is START_ARRAY\n// after\nEvent ev = parser.next();\nString s = (ev == Event.VALUE_STRING || ev == Event.KEY_NAME || ev == Event.VALUE_NUMBER)\n    ? parser.getString()\n    : null;","handlingStrategy":"type-guard","validationCode":"// before reading\nEvent ev = /* last event returned by parser.next() */;\nboolean canReadString = (ev == Event.KEY_NAME || ev == Event.VALUE_STRING || ev == Event.VALUE_NUMBER);","typeGuard":"boolean isStringReadable(Event ev) {\n    return ev == Event.KEY_NAME || ev == Event.VALUE_STRING || ev == Event.VALUE_NUMBER;\n}","tryCatchPattern":"try {\n    String s = parser.getString();\n} catch (IllegalStateException e) {\n    // wrong parser state: re-check the current Event and use the proper accessor\n}","preventionTips":["Always track the Event returned by next() before calling state-specific accessors","Route tokens through a switch on Event rather than calling getString() unconditionally","Add assertions on the current event during development of parser-walking code"],"tags":["json","illegal-state","json-path","parser-state"],"backgroundTag":"invalid-state-transition","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"}