stanfordnlp/CoreNLP · error · IllegalArgumentException

Invalid number of arguments to ${name}

Error message

Invalid number of arguments to ${name}

What it means

This IllegalArgumentException is thrown by the anonymous ValueFunction bound to a temporal environment function (the ISO/WEEK/DAY-family function in GenericTimeExpressionPatterns.createTemporalFunction) when its apply() is called with an argument count it does not accept. These CoreMapExpressionWrapper functions are bound into the pattern environment used by SUTime rule files, and each expects exactly the declared number of arguments; 'Invalid number of arguments to <name>' signals the arity contract was violated at expression-evaluation time.

Solutions

  1. Count the arguments passed to the function in your SUTime rules/expressions file and pass exactly the number the function expects (check the function's binding in GenericTimeExpressionPatterns for the expected in.size()).
  2. Check for optional/empty capture groups in the surrounding TokensRegex pattern that yield missing or extra values in the argument list.
  3. If calling programmatically, assert in.size() matches before invoking Value.apply.
  4. Pin/verify the Stanford CoreNLP version matches the rules-file format you are using (function arities have changed across releases).

Example fix

// before (rules file)
$ISOSimpleDate( )
// after
$ISOSimpleDate( $0 )
Defensive patterns

Strategy: validation

Validate before calling

if (args == null || args.size() != 1) {
  throw new IllegalArgumentException("Expected exactly 1 argument, got " + (args == null ? 0 : args.size()));
}

Type guard

boolean hasValidArity(java.util.List<?> in, int expected) {
  return in != null && in.size() == expected;
}

Try / catch

try {
  Value v = func.apply(env, args);
} catch (IllegalArgumentException e) {
  if (e.getMessage().contains("Invalid number of arguments")) {
    // log arg count and correct the rules expression
  } else { throw e; }
}

Prevention

When it happens

Trigger: Calling the bound function (via a SUTime rules file expression like $func(...) or TokensRegex/env.eval) with zero arguments or more than the expected count, e.g. FUNC() or FUNC(a,b,c), so in.size() != expected inside Value.apply.

Common situations: Hand-edited or customized SUTime .rules/expressions files passing wrong arity; regex capture groups that produce empty or extra argument lists; programmatic Env.bind/Expressions usage calling apply() directly with a constructed List<Value> of the wrong size; pattern changes after a CoreNLP upgrade altering expected arguments.

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


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

Appendix: source

Thrown at src/edu/stanford/nlp/time/GenericTimeExpressionPatterns.java:205

                    if (durationEnd != null) {
                      duration = durationEnd;
                    } else {
                      duration = new SUTime.InexactDuration(durationUnit);
                    }
                  }
                  else if (durationEnd != null) { duration = new SUTime.DurationRange(durationStart, durationEnd); }

                  // Add begin and end times
                  SUTime.Time beginTime = (in.size() > 3)? (SUTime.Time) in.get(3).get():null;
                  SUTime.Time endTime = (in.size() > 4)? (SUTime.Time) in.get(4).get():null;
                  SUTime.Temporal temporal = addEndPoints(duration, beginTime, endTime);
                  if (temporal instanceof SUTime.Range) {
                    return new Expressions.PrimitiveValue("RANGE", temporal);
                  } else {
                    return new Expressions.PrimitiveValue("DURATION", temporal);
                  }
                } else {
                  throw new IllegalArgumentException("Invalid number of arguments to " + name);
                }
              }
            }
    ));
    env.bind("DayOfWeek", new Expressions.PrimitiveValue<ValueFunction>(
            Expressions.TYPE_FUNCTION,
            new ValueFunctions.NamedValueFunction("DayOfWeek") {
              @Override
              public boolean checkArgs(List<Value> in) {
                if (in.size() != 1) {
                  return false;
                }
                if (in.get(0) == null || !(in.get(0).get() instanceof Number)) {
                  return false;
                }
                return true;
              }
              public Value apply(Env env, List<Value> in) {

View on GitHub (pinned to 1b7edd19c4)