stanfordnlp/CoreNLP · error · IllegalArgumentException

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

Error message

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

What it means

Thrown by the same MakePeriodicTemporalSet-style ValueFunction in GenericTimeExpressionPatterns when the optional second argument (arg1), if present and non-null, is not a List<CoreMap>. It expects arg1 to be a quantifier expression represented as a list of CoreMap annotations whose text (lowercased) becomes the quant string; any other type triggers 'Type mismatch on arg1: Cannot apply <this> to <in>'.

Solutions

  1. Pass the quantifier as the annotated capture group (List<CoreMap>), e.g. the QUANT variable from your pattern, not a raw string literal.
  2. If you only have a string, wrap/annotate it or omit arg1 entirely (it is optional — guard with in.size() >= 2 and non-null).
  3. Verify the pattern still binds the quantifier group as a token list after any regex edits.
  4. If calling programmatically, construct arg1 as a list of CoreMap annotations whose TextAnnotation holds the quantifier.

Example fix

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

Strategy: type-guard

Validate before calling

if (args.size() >= 2 && args.get(1) != null
    && !(args.get(1).get() instanceof java.util.List)) {
  throw new IllegalArgumentException("arg1 (quantifier) must be a List<CoreMap>");
}

Type guard

boolean isCoreMapListArg(Object v) {
  return v instanceof java.util.List<?, ?> list
      && (list.isEmpty() || list.get(0) instanceof edu.stanford.nlp.util.CoreMap);
}

Try / catch

try {
  Value v = periodicFn.apply(env, args);
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("Type mismatch on arg1")) {
    // drop arg1 or pass the annotated QUANT group instead
  } else { throw e; }
}

Prevention

When it happens

Trigger: Calling the function with a second argument that is a String, Number, Temporal, or other value rather than a List<CoreMap> — typically passing a plain text variable or literal like "every" instead of the quantifier's annotated token list.

Common situations: Rules files passing a literal quantifier string instead of the matched QUANT group; capture-group variable reshaping after editing a pattern so the group no longer yields a CoreMap list; programmatic Value.apply calls building in.get(1) as a PrimitiveValue(String).

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/78e283626bcfd058. Report an issue: GitHub.

Appendix: source

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

                  } 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) {
                    Number arg2 = (Number) in.get(2).get();
                    if (arg2 != null) {
                      scale = arg2.intValue();
                    }
                  }
                  SUTime.Duration period = temporal.getPeriod();
                  if (period != null && scale != 1) {
                    period = period.multiplyBy(scale);
                  }
                  return new Expressions.PrimitiveValue("PeriodicTemporalSet",
                          new SUTime.PeriodicTemporalSet(temporal,period,quant,null/*"P1X"*/));
                } else {
                  throw new IllegalArgumentException("Invalid number of arguments to " + name);
                }
              }

View on GitHub (pinned to 1b7edd19c4)