{"record":{"id":"fbac2e39606b17a7","repo":"json-path/JsonPath","slug":"function-with-name-does-not-exist","errorCode":null,"errorMessage":"Function with name:  does not exist.","messagePattern":"Function with name:  does not exist\\.","errorType":"exception","errorClass":"InvalidPathException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/internal/function/PathFunctionFactory.java","lineNumber":79,"sourceCode":"\n    /**\n     * Returns the function by name or throws InvalidPathException if function not found.\n     *\n     * @see #FUNCTIONS\n     * @see PathFunction\n     *\n     * @param name\n     *      The name of the function\n     *\n     * @return\n     *      The implementation of a function\n     *\n     * @throws InvalidPathException\n     */\n    public static PathFunction newFunction(String name) throws InvalidPathException {\n        Class functionClazz = FUNCTIONS.get(name);\n        if(functionClazz == null){\n            throw new InvalidPathException(\"Function with name: \" + name + \" does not exist.\");\n        } else {\n            try {\n                return (PathFunction)functionClazz.newInstance();\n            } catch (Exception e) {\n                throw new InvalidPathException(\"Function of name: \" + name + \" cannot be created\", e);\n            }\n        }\n    }\n}\n","sourceCodeStart":61,"sourceCodeEnd":89,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/internal/function/PathFunctionFactory.java#L61-L89","documentation":"PathFunctionFactory.newFunction(name) looks up a registered function class by name (e.g. length(), sum(), concat()). If the name is not in the FUNCTIONS map, it throws InvalidPathException('Function with name: X does not exist.'). This guards the function-call syntax in paths like $.books.length().","triggerScenarios":"A path uses function-call syntax with an unknown or misspelled function name — e.g. $.items.size() or $.arr.count() — passed to JsonPath.read()/compile(). Also occurs when a custom function is not registered via PathFunctionFactory.registerFunction().","commonSituations":"Confusing Java-ish names (size, count) with JsonPath functions (length, sum, avg, min, max, stddev, concat, append), using functions from non-default modules that were never registered, or typos in dynamic path strings.","solutions":["Use a supported built-in function name: length(), sum(), avg(), min(), max(), stddev(), concat(...), append(...).","For a custom function, register it first: PathFunctionFactory.registerFunction(\"myfunc\", MyFunc.class).","Print the path and check the segment after '.' before '()' for typos.","Catch InvalidPathException and validate user-supplied paths against a whitelist of allowed functions."],"exampleFix":"// before\nInteger n = JsonPath.read(json, \"$.books.size()\"); // no such function\n// after\nInteger n = JsonPath.read(json, \"$.books.length()\");","handlingStrategy":"validation","validationCode":"Set<String> allowed = Set.of(\"length\",\"sum\",\"avg\",\"min\",\"max\",\"stddev\",\"concat\",\"append\");\nfor (String f : extractFunctionNames(path)) if (!allowed.contains(f)) throw new InvalidPathException(\"Unknown function: \" + f);","typeGuard":null,"tryCatchPattern":"try {\n    return JsonPath.read(json, path);\n} catch (InvalidPathException e) {\n    if (e.getMessage().contains(\"does not exist\")) { /* unknown function: report name */ }\n    throw e;\n}","preventionTips":["Whitelist allowed functions in user-facing path inputs","Remember the names: length/sum/avg/min/max/stddev/concat/append — not size/count","Register custom functions with PathFunctionFactory.registerFunction before use"],"tags":["json-path","invalid-path","function"],"backgroundTag":"resource-not-found","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"}