stanfordnlp/CoreNLP · error · IllegalArgumentException

Type mismatch on arg0: Cannot apply

Error message

Type mismatch on arg0: Cannot apply ${this} to ${in}

What it means

Thrown by the MakePeriodicTemporalSet-style ValueFunction (the quant/scale temporal function bound in GenericTimeExpressionPatterns) when its first argument (arg0) is neither an SUTime.Temporal nor a TimeExpression. The function must extract a Temporal from arg0 to build a periodic temporal set; anything else triggers 'Type mismatch on arg0: Cannot apply <this> to <in>'.

Solutions

  1. Ensure arg0 is the temporal value: pass the variable bound to a Temporal or TimeExpression (e.g. the annotated time group), not a plain text/string group.
  2. If you have a string/number, convert it first via an appropriate temporal function or SUTime parsing before passing it.
  3. Check the composed expression chain so the first argument is not a PrimitiveValue of the wrong type.
  4. Debug by printing the evaluated argument types in your rules environment before the call.

Example fix

// before
$MakePeriodicTemporalSet( $text, "every" )
// after
$MakePeriodicTemporalSet( $temporal, "every" )
Defensive patterns

Strategy: type-guard

Validate before calling

Object first = args.get(0).get();
if (!(first instanceof edu.stanford.nlp.time.SUTime.Temporal)
    && !(first instanceof edu.stanford.nlp.time.TimeExpression)) {
  throw new IllegalArgumentException("arg0 must be a Temporal or TimeExpression");
}

Type guard

boolean isTemporalArg(Object v) {
  return v instanceof edu.stanford.nlp.time.SUTime.Temporal
      || v instanceof edu.stanford.nlp.time.TimeExpression;
}

Try / catch

try {
  Value v = periodicFn.apply(env, args);
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("Type mismatch on arg0")) {
    // convert or select the correct temporal variable before retrying
  } else { throw e; }
}

Prevention

When it happens

Trigger: Calling the function whose first argument evaluates to a String, Number, List<Value>, or null instead of a Temporal or TimeExpression — e.g. passing a text capture group (string) rather than the temporal produced by a TIME/DATE annotation, or passing the wrong variable in a rules file.

Common situations: SUTime rules files where the wrong capture-group variable is passed ($1 vs the temporal group); composing functions so a nested function returns a DURATION primitive instead of a Temporal; programmatic evaluation feeding raw values instead of TimeExpression objects; upgrade changes altering what a group contains.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

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

                if (in.get(1) == null ||
                        (!(in.get(1).get() instanceof String) && !(in.get(1).get() instanceof List))) {
                  return false;
                }
                if (in.get(2) == null || !(in.get(2).get() instanceof Number)) {
                  return false;
                }
                return true;
              }
              public Value apply(Env env, List<Value> in) {
                if (in.size() >= 1) {
                  SUTime.Temporal temporal = null;
                  Object t = in.get(0).get();
                  if (t instanceof SUTime.Temporal) {
                    temporal = (SUTime.Temporal) in.get(0).get();
                  } else if (t instanceof TimeExpression) {
                    temporal = ((TimeExpression) t).getTemporal();
                  } else {
                    throw new IllegalArgumentException("Type mismatch on arg0: Cannot apply " + this + " to " + in);
                  }
                  String quant = null;
                  int scale = 1;
                  if (in.size() >= 2 && in.get(1) != null) {
                    Object arg1 = in.get(1).get();
                    if (arg1 instanceof String) {
                      quant = (String) arg1;
                    } else if (arg1 instanceof List) {
                      List<CoreMap> cms = (List<CoreMap>) arg1;
                      quant = ChunkAnnotationUtils.getTokenText(cms, CoreAnnotations.TextAnnotation.class);
                      if (quant != null) {
                        quant = quant.toLowerCase();
                      }
                    } else {
                      throw new IllegalArgumentException("Type mismatch on arg1: Cannot apply " + this + " to " + in);
                    }
                  }
                  if (in.size() >= 3 && in.get(2) != null) {

View on GitHub (pinned to 1b7edd19c4)