{"record":{"id":"64fa375ad221ea45","repo":"json-path/JsonPath","slug":"failed-to-parse-token-in-arrayindexoperation","errorCode":null,"errorMessage":"Failed to parse token in ArrayIndexOperation: ","messagePattern":"Failed to parse token in ArrayIndexOperation: ","errorType":"exception","errorClass":"InvalidPathException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/internal/path/ArrayIndexOperation.java","lineNumber":63,"sourceCode":"            if (!isDigit(c) && c != ',' && c != ' ' && c != '-') {\n                throw new InvalidPathException(\"Failed to parse ArrayIndexOperation: \" + operation);\n            }\n        }\n        String[] tokens = COMMA.split(operation, -1);\n\n        List<Integer> tempIndexes = new ArrayList<Integer>(tokens.length);\n        for (String token : tokens) {\n            tempIndexes.add(parseInteger(token));\n        }\n\n        return new ArrayIndexOperation(tempIndexes);\n    }\n\n    private static Integer parseInteger(String token) {\n        try {\n            return Integer.parseInt(token);\n        } catch (Exception e){\n            throw new InvalidPathException(\"Failed to parse token in ArrayIndexOperation: \" + token, e);\n        }\n    }\n}\n","sourceCodeStart":45,"sourceCodeEnd":67,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/internal/path/ArrayIndexOperation.java#L45-L67","documentation":"After character validation, ArrayIndexOperation.parse() splits the bracket content on commas and parses each token with Integer.parseInt via parseInteger(). A non-integer token (empty string, out-of-int-range number, stray spaces-only token like '1,,2' producing an empty token) raises InvalidPathException('Failed to parse token in ArrayIndexOperation: <token>').","triggerScenarios":"Bracket operations like [1,,2] (double comma → empty token), [ 999999999999 ] (overflow beyond int), or [,1] (leading comma) passed to JsonPath.read()/compile().","commonSituations":"Programmatically generated index lists joined with commas where an empty entry slips in, very large indices copied from other systems, or hand-edited paths with typos.","solutions":["Remove double/leading/trailing commas from the bracket operation.","Keep each index within the 32-bit int range and within the array bounds.","Validate tokens with a regex like ^-?\\\\d+(\\\\s*,\\\\s*-?\\\\d+)*$ before building the path.","Catch InvalidPathException and log the offending token to locate the malformed segment."],"exampleFix":"// before\nJsonPath.read(json, \"$.items[1,,2]\"); // empty token\n// after\nJsonPath.read(json, \"$.items[1,2]\");","handlingStrategy":"validation","validationCode":"if (!operation.trim().matches(\"-?\\\\d+(\\\\s*,\\\\s*-?\\\\d+)*\")) throw new InvalidPathException(\"Bad index list: \" + operation);","typeGuard":null,"tryCatchPattern":"try {\n    JsonPath.compile(path);\n} catch (InvalidPathException e) {\n    if (e.getMessage().startsWith(\"Failed to parse token in ArrayIndexOperation\")) { /* fix token: empty or overflow */ }\n    throw e;\n}","preventionTips":["Avoid double/leading/trailing commas in index lists","Keep indices within 32-bit int range","Validate generated index lists with a regex before joining into a path"],"tags":["json-path","invalid-path","syntax"],"backgroundTag":"invalid-argument-format","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"}