stanfordnlp/CoreNLP · error · RuntimeException

Cannot find function matching args

Error message

Cannot find function matching args: ${function}
Args are: ${evaled}
Options are:
${fs}

What it means

The function name resolved to something callable, but none of its overloads/signatures accept the argument types actually evaluated. The library builds a diagnostic message listing the evaluated args and the candidate signatures it considered, then throws.

Solutions

  1. Match argument count and types to one of the printed 'Options are:' signatures in the exception message
  2. Add explicit type coercion in the rule, e.g. pass `1` instead of `"1"` or wrap args in INT()/STRING() style conversions if available
  3. Register an additional ValueFunction overload accepting the argument types you pass
  4. Check whether a library upgrade changed the function's signature

Example fix

// before
$FUNC("5")   // expects Integer
// after
$FUNC(5)
Defensive patterns

Strategy: type-guard

Validate before calling

Object f = ValueFunctions.lookupFunctionObject(env, functionName);
// compare expected arg types against evaluated params before invoking
for (Expression p : params) {
    Object v = p.evaluate(env).get();
    // assert v matches a declared signature type
}

Try / catch

try {
    Value v = expr.evaluate(env, args);
} catch (RuntimeException e) {
    if (e.getMessage().contains("Cannot find function matching args")) {
        // parse 'Options are:' from message and log expected signatures
    } else throw e;
}

Prevention

When it happens

Trigger: Evaluating `FUNC(a, b)` where FUNC exists but no registered ValueFunction or reflected method/constructor matches the number and types of the evaluated parameters — e.g. passing a String where an Integer is expected, or the wrong argument count.

Common situations: Passing string literals where numeric literals are required (or vice versa) in TokensRegex expressions, calling a Java static method with mismatched parameter types, or overload changes after a CoreNLP upgrade.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/db156c7bdcacf41f. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/ling/tokensregex/types/Expressions.java:951

        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) {
          if (f.checkArgs(evaled)) {
            return f.apply(env, evaled);
          }
        }
        StringBuilder sb = new StringBuilder();
        sb.append("Cannot find function matching args: " + function + NEWLINE);
        sb.append("Args are: " + StringUtils.join(evaled, ",") + NEWLINE);
        if (fs.size() > 0) {
          sb.append("Options are:\n" + StringUtils.join(fs, NEWLINE));
        } else {
          sb.append("No options");
        }
        throw new RuntimeException(sb.toString());
      } else if (funcValue instanceof Class) {
        Class c = (Class) funcValue;
        List<Value> evaled = new ArrayList<>();
        for (Expression param:params) {
          evaled.add(param.evaluate(env, args));
        }
        Class[] paramTypes = new Class[params.size()];
        Object[] objs = new Object[params.size()];
        boolean paramsNotNull = true;
        for (int i = 0; i < params.size(); i++) {
          Value v = evaled.get(i);
          if (v != null) {
            objs[i] = v.get();
            if (objs[i] != null) {
              paramTypes[i] = objs[i].getClass();
            } else {
              paramTypes[i] = null;
              paramsNotNull = false;

View on GitHub (pinned to 1b7edd19c4)