{"record":{"id":"984329491af24f58","repo":"stanfordnlp/CoreNLP","slug":"unknown-function-function","errorCode":null,"errorMessage":"Unknown function ${function}","messagePattern":"Unknown function (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/types/Expressions.java","lineNumber":920,"sourceCode":"      for (Expression param:params) {\n        Expression simplified = param.simplify(env);\n        simplifiedParams.add(simplified);\n        if (!(simplified.hasValue())) {\n          paramsAllHasValue = false;\n        }\n      }\n      Expression res = new FunctionCallExpression(function, simplifiedParams);\n      if (paramsAllHasValue) {\n        return res.evaluate(env);\n      } else {\n        return res;\n      }\n    }\n\n    public Value evaluate(Env env, Object... args) {\n      Object funcValue = ValueFunctions.lookupFunctionObject(env, function);\n      if (funcValue == null) {\n        throw new RuntimeException(\"Unknown function \" + function);\n      }\n      if (funcValue instanceof Value) {\n        funcValue = ((Value) funcValue).evaluate(env, args).get();\n      }\n      if (funcValue instanceof ValueFunction) {\n        ValueFunction f = (ValueFunction) funcValue;\n        List<Value> evaled = new ArrayList<>();\n        for (Expression param:params) {\n          evaled.add(param.evaluate(env, args));\n        }\n        return f.apply(env, evaled);\n      } else if (funcValue instanceof Collection) {\n        List<Value> evaled = new ArrayList<>();\n        for (Expression param:params) {\n          evaled.add(param.evaluate(env, args));\n        }\n        Collection<ValueFunction> fs = (Collection<ValueFunction>) funcValue;\n        for (ValueFunction f:fs) {","sourceCodeStart":902,"sourceCodeEnd":938,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/types/Expressions.java#L902-L938","documentation":"When evaluating a function-call expression, the library looks the function name up in the environment via ValueFunctions.lookupFunctionObject. If the name is not bound to any function, class, or function object, it cannot be invoked and throws RuntimeException(\"Unknown function ...\").","triggerScenarios":"Evaluating an expression like `FOO(...)` where `FOO` was never registered with env.bind/registerFunction, the name is misspelled, or the function was bound under a different Env than the one used at evaluation time.","commonSituations":"TokensRegex rules referencing custom Java functions (e.g. FROMCLASS or registered ValueFunctions) without calling env.bind(...), or rules moved between pipelines where the function registration code was not ported.","solutions":["Register the function in the Env before evaluation, e.g. `env.bind(\"FUNCTION_NAME\", new MyValueFunction())`","Check spelling/case of the function name in the rule against registered names","Verify the same Env instance (with the binding) is passed to evaluate()","If using `CLASS#method` syntax, confirm the fully-qualified class name is on the classpath"],"exampleFix":"// before\nValue v = expr.evaluate(new Env()); // function never bound\n// after\nEnv env = new Env();\nenv.bind(\"MYFUNC\", new MyValueFunction());\nValue v = expr.evaluate(env);","handlingStrategy":"validation","validationCode":"if (ValueFunctions.lookupFunctionObject(env, functionName) == null) {\n    throw new IllegalStateException(\"Function not bound in env: \" + functionName);\n}","typeGuard":null,"tryCatchPattern":"try {\n    Value v = expr.evaluate(env, args);\n} catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"Unknown function \")) {\n        // bind or correct the function name, then retry once\n    } else throw e;\n}","preventionTips":["Register all custom functions in one bootstrap method called before rule loading","Keep a registry of bound function names and validate rules against it at load time","Share a single Env instance across rule compilation and evaluation"],"tags":["tokensregex","expression-language","unknown-function"],"backgroundTag":"resource-not-found","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}