stanfordnlp/CoreNLP · error · IllegalArgumentException
arguments expected, got
Error message
${nargs} arguments expected, got ${in.size()} What it means
ValueFunctions.NumericFunction.apply validates argument count before computing: if the function declares a fixed nargs > 0 and the incoming list size differs, it throws this IllegalArgumentException. It enforces arity for numeric functions (e.g. MIN/MAX with fixed argument counts) in TokensRegex expressions.
Solutions
- Count the function's required arguments and supply exactly nargs values in the call.
- Log/inspect in.size() from the exception message to see how many were actually passed and where the extras/missing ones come from.
- If arguments come from capture groups, guard with a count check before invoking the function.
- Use a variadic function (nargs == -1 / nargs <= 0 path) if a variable argument count is intended.
Example fix
// before MIN() // 0 args, function requires 2 // after MIN($left, $right) // matches nargs == 2
Defensive patterns
Strategy: validation
Validate before calling
if (args.size() != expectedNargs) {
throw new IllegalStateException("MIN/MAX function needs " + expectedNargs + " args, got " + args.size());
} Type guard
static boolean hasArity(java.util.List<?> in, int nargs) {
return nargs <= 0 || in.size() == nargs;
} Try / catch
try { Value v = func.apply(env, in); }
catch (IllegalArgumentException ex) {
if (ex.getMessage().contains("arguments expected, got")) {
log.error("Arity mismatch calling numeric function: " + ex.getMessage());
}
throw ex;
} Prevention
- Check the function's declared nargs before calling
- Count arguments in rule expressions carefully after edits
- Guard dynamic argument lists (capture groups) with size checks
When it happens
Trigger: Calling a TokensRegex numeric function (e.g. in a rule's action or expression) with the wrong number of arguments — too few from missing bindings, too many from extra comma-separated expressions; binding list built programmatically with wrong size.
Common situations: Rule expressions like FUNC{...} where the expected fixed arity doesn't match; captured-groups list feeding a numeric function with a variable count; miscounted arguments after editing a rule.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- 2 arguments expected, got
- Invalid number of arguments to
- Annotation field cannot be null
- : Entry has multiple types for : . Taking type to be
- Attribute already defined:
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/97f9155aa8676261.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ling/tokensregex/types/ValueFunctions.java:184
public abstract Number compute(Number...ns);
@Override
public boolean checkArgs(List<Value> in) {
if (nargs > 0 && in.size() != nargs) {
return false;
}
for (Value v : in) {
if (v == null || !(v.get() instanceof Number)) {
return false;
}
}
return true;
}
@Override
public Value apply(Env env, List<Value> in) {
if (nargs > 0 && in.size() != nargs) {
throw new IllegalArgumentException(nargs + " arguments expected, got " + in.size());
}
Number[] numbers = new Number[in.size()];
for (int i = 0; i < in.size(); i++) {
numbers[i] = (Number) in.get(i).get();
}
Number res = compute(numbers);
return new Expressions.PrimitiveValue(resultTypeName, res);
}
}
public static final ValueFunction ADD_FUNCTION = new NumericFunction("ADD", 2) {
@Override
public Number compute(Number... in) {
if (isInteger(in[0]) && isInteger(in[1])) {
return in[0].longValue() + in[1].longValue();
} else {
return in[0].doubleValue() + in[1].doubleValue();
}View on GitHub (pinned to 1b7edd19c4)