{"record":{"id":"ceda9e9bd0718a14","repo":"stanfordnlp/CoreNLP","slug":"type-mismatch-on-arg0-cannot-apply-this-to-i-ceda9e","errorCode":null,"errorMessage":"Type mismatch on arg0: Cannot apply ${this} to ${in}","messagePattern":"Type mismatch on arg0: Cannot apply (.+?) to (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/time/GenericTimeExpressionPatterns.java","lineNumber":289,"sourceCode":"                if (in.get(1) == null ||\n                        (!(in.get(1).get() instanceof String) && !(in.get(1).get() instanceof List))) {\n                  return false;\n                }\n                if (in.get(2) == null || !(in.get(2).get() instanceof Number)) {\n                  return false;\n                }\n                return true;\n              }\n              public Value apply(Env env, List<Value> in) {\n                if (in.size() >= 1) {\n                  SUTime.Temporal temporal = null;\n                  Object t = in.get(0).get();\n                  if (t instanceof SUTime.Temporal) {\n                    temporal = (SUTime.Temporal) in.get(0).get();\n                  } else if (t instanceof TimeExpression) {\n                    temporal = ((TimeExpression) t).getTemporal();\n                  } else {\n                    throw new IllegalArgumentException(\"Type mismatch on arg0: Cannot apply \" + this + \" to \" + in);\n                  }\n                  String quant = null;\n                  int scale = 1;\n                  if (in.size() >= 2 && in.get(1) != null) {\n                    Object arg1 = in.get(1).get();\n                    if (arg1 instanceof String) {\n                      quant = (String) arg1;\n                    } else if (arg1 instanceof List) {\n                      List<CoreMap> cms = (List<CoreMap>) arg1;\n                      quant = ChunkAnnotationUtils.getTokenText(cms, CoreAnnotations.TextAnnotation.class);\n                      if (quant != null) {\n                        quant = quant.toLowerCase();\n                      }\n                    } else {\n                      throw new IllegalArgumentException(\"Type mismatch on arg1: Cannot apply \" + this + \" to \" + in);\n                    }\n                  }\n                  if (in.size() >= 3 && in.get(2) != null) {","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/time/GenericTimeExpressionPatterns.java#L271-L307","documentation":"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>'.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","If you have a string/number, convert it first via an appropriate temporal function or SUTime parsing before passing it.","Check the composed expression chain so the first argument is not a PrimitiveValue of the wrong type.","Debug by printing the evaluated argument types in your rules environment before the call."],"exampleFix":"// before\n$MakePeriodicTemporalSet( $text, \"every\" )\n// after\n$MakePeriodicTemporalSet( $temporal, \"every\" )","handlingStrategy":"type-guard","validationCode":"Object first = args.get(0).get();\nif (!(first instanceof edu.stanford.nlp.time.SUTime.Temporal)\n    && !(first instanceof edu.stanford.nlp.time.TimeExpression)) {\n  throw new IllegalArgumentException(\"arg0 must be a Temporal or TimeExpression\");\n}","typeGuard":"boolean isTemporalArg(Object v) {\n  return v instanceof edu.stanford.nlp.time.SUTime.Temporal\n      || v instanceof edu.stanford.nlp.time.TimeExpression;\n}","tryCatchPattern":"try {\n  Value v = periodicFn.apply(env, args);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Type mismatch on arg0\")) {\n    // convert or select the correct temporal variable before retrying\n  } else { throw e; }\n}","preventionTips":["Pass the temporal/TimeExpression-bound variable, not a text capture group, as the first argument.","Trace nested function return types in composed rules expressions.","Add assertions or debug prints of argument types when authoring rules.","Re-verify group variable bindings after any pattern edits."],"tags":["java","sutime","type-mismatch","temporal"],"backgroundTag":"type-mismatch","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}