stanfordnlp/CoreNLP · error · RuntimeException
Unknown function
Error message
Unknown function ${function} What it means
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 ...").
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
Example fix
// before
Value v = expr.evaluate(new Env()); // function never bound
// after
Env env = new Env();
env.bind("MYFUNC", new MyValueFunction());
Value v = expr.evaluate(env); Defensive patterns
Strategy: validation
Validate before calling
if (ValueFunctions.lookupFunctionObject(env, functionName) == null) {
throw new IllegalStateException("Function not bound in env: " + functionName);
} Try / catch
try {
Value v = expr.evaluate(env, args);
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Unknown function ")) {
// bind or correct the function name, then retry once
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Cannot find function matching args
- Expression was not evaluated....
- Unsupported function value
- 2 arguments expected, got
- Annotation field cannot be null
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/984329491af24f58.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ling/tokensregex/types/Expressions.java:920
for (Expression param:params) {
Expression simplified = param.simplify(env);
simplifiedParams.add(simplified);
if (!(simplified.hasValue())) {
paramsAllHasValue = false;
}
}
Expression res = new FunctionCallExpression(function, simplifiedParams);
if (paramsAllHasValue) {
return res.evaluate(env);
} else {
return res;
}
}
public Value evaluate(Env env, Object... args) {
Object funcValue = ValueFunctions.lookupFunctionObject(env, function);
if (funcValue == null) {
throw new RuntimeException("Unknown function " + function);
}
if (funcValue instanceof Value) {
funcValue = ((Value) funcValue).evaluate(env, args).get();
}
if (funcValue instanceof ValueFunction) {
ValueFunction f = (ValueFunction) funcValue;
List<Value> evaled = new ArrayList<>();
for (Expression param:params) {
evaled.add(param.evaluate(env, args));
}
return f.apply(env, evaled);
} else if (funcValue instanceof Collection) {
List<Value> evaled = new ArrayList<>();
for (Expression param:params) {
evaled.add(param.evaluate(env, args));
}
Collection<ValueFunction> fs = (Collection<ValueFunction>) funcValue;
for (ValueFunction f:fs) {View on GitHub (pinned to 1b7edd19c4)