{"record":{"id":"7a7c61b95ce79eda","repo":"json-path/JsonPath","slug":"arguments-to-function-are-not-closed-properly","errorCode":null,"errorMessage":"Arguments to function: '' are not closed properly.","messagePattern":"Arguments to function: '' are not closed properly\\.","errorType":"exception","errorClass":"InvalidPathException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java","lineNumber":226,"sourceCode":"            endPosition = path.length();\n        }\n\n\n        List<Parameter> functionParameters = null;\n        if (isFunction) {\n            int parenthesis_count = 1;\n            for(int i = readPosition + 1; i < path.length(); i++){\n                if (path.charAt(i) == CLOSE_PARENTHESIS)\n                    parenthesis_count--;\n                else if (path.charAt(i) == OPEN_PARENTHESIS)\n                    parenthesis_count++;\n                if (parenthesis_count == 0)\n                    break;\n            }\n\n            if (parenthesis_count != 0){\n                String functionName = path.subSequence(startPosition, endPosition).toString();\n                throw new InvalidPathException(\"Arguments to function: '\" + functionName + \"' are not closed properly.\");\n            }\n\n            if (path.inBounds(readPosition+1)) {\n                // read the next token to determine if we have a simple no-args function call\n                char c = path.charAt(readPosition + 1);\n                if (c != CLOSE_PARENTHESIS) {\n                    path.setPosition(endPosition+1);\n                    // parse the arguments of the function - arguments that are inner queries or JSON document(s)\n                    String functionName = path.subSequence(startPosition, endPosition).toString();\n                    functionParameters = parseFunctionParameters(functionName);\n                } else {\n                    path.setPosition(readPosition + 1);\n                }\n            }\n            else {\n                path.setPosition(readPosition);\n            }\n        }","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java#L208-L244","documentation":"When the compiler scans a function-call token `name(...)`, it tracks parenthesis nesting; if the closing parenthesis is never found before the path string ends, the arguments are considered unclosed and compilation throws InvalidPathException naming the function.","triggerScenarios":"Paths with unbalanced parentheses such as `$.length()` written as `$.length(`, nested calls missing a close like `$.sum((@.x, @.y`, or truncation of a long path string.","commonSituations":"Hand-written function paths (length, min, max, avg, concat, etc.) with typos; string truncation in logs/configs; generated filter expressions where the closing paren was appended after a conditional that got skipped.","solutions":["Balance the parentheses in the path, e.g. `$.length(` → `$.length()`.","For filters with functions, ensure the whole predicate is closed: `$[?(@.x.length() > 2)]`.","When generating paths in code, count/verify parentheses before compiling, and log the full untruncated path on failure."],"exampleFix":"// before\nJsonPath.read(json, \"$.items.length(\");\n// after\nJsonPath.read(json, \"$.items.length()\");","handlingStrategy":"validation","validationCode":"boolean parensBalanced(String path) {\n    int n = 0;\n    for (char c : path.toCharArray()) {\n        if (c == '(') n++;\n        if (c == ')') n--;\n        if (n < 0) return false;\n    }\n    return n == 0;\n}","typeGuard":null,"tryCatchPattern":"try {\n    return JsonPath.read(json, path);\n} catch (InvalidPathException e) {\n    throw new IllegalArgumentException(\"Unclosed function arguments in path: \" + path, e);\n}","preventionTips":["Count parentheses when generating function-call paths.","Build filter+function expressions with helper methods instead of raw string concatenation.","Avoid truncating long path strings in config or logs that are later re-parsed."],"tags":["json-path","invalid-path","function","syntax"],"backgroundTag":"invalid-path-syntax","analyzedSha":"62a4c9f0f65ba3f625aa0867d64c528ba72d09ec","analyzedAt":"2026-09-11T11:36:00.448Z","contentChangedAt":"2026-09-11T11:36:00.448Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}