{"record":{"id":"78e283626bcfd058","repo":"stanfordnlp/CoreNLP","slug":"type-mismatch-on-arg1-cannot-apply-this-to-i-78e283","errorCode":null,"errorMessage":"Type mismatch on arg1: Cannot apply ${this} to ${in}","messagePattern":"Type mismatch on arg1: Cannot apply (.+?) to (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/time/GenericTimeExpressionPatterns.java","lineNumber":304,"sourceCode":"                  } 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) {\n                    Number arg2 = (Number) in.get(2).get();\n                    if (arg2 != null) {\n                      scale = arg2.intValue();\n                    }\n                  }\n                  SUTime.Duration period = temporal.getPeriod();\n                  if (period != null && scale != 1) {\n                    period = period.multiplyBy(scale);\n                  }\n                  return new Expressions.PrimitiveValue(\"PeriodicTemporalSet\",\n                          new SUTime.PeriodicTemporalSet(temporal,period,quant,null/*\"P1X\"*/));\n                } else {\n                  throw new IllegalArgumentException(\"Invalid number of arguments to \" + name);\n                }\n              }","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/time/GenericTimeExpressionPatterns.java#L286-L322","documentation":"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>'.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Pass the quantifier as the annotated capture group (List<CoreMap>), e.g. the QUANT variable from your pattern, not a raw string literal.","If you only have a string, wrap/annotate it or omit arg1 entirely (it is optional — guard with in.size() >= 2 and non-null).","Verify the pattern still binds the quantifier group as a token list after any regex edits.","If calling programmatically, construct arg1 as a list of CoreMap annotations whose TextAnnotation holds the quantifier."],"exampleFix":"// before\n$MakePeriodicTemporalSet( $temporal, \"every\", 1 )\n// after\n$MakePeriodicTemporalSet( $temporal, $quant )","handlingStrategy":"type-guard","validationCode":"if (args.size() >= 2 && args.get(1) != null\n    && !(args.get(1).get() instanceof java.util.List)) {\n  throw new IllegalArgumentException(\"arg1 (quantifier) must be a List<CoreMap>\");\n}","typeGuard":"boolean isCoreMapListArg(Object v) {\n  return v instanceof java.util.List<?, ?> list\n      && (list.isEmpty() || list.get(0) instanceof edu.stanford.nlp.util.CoreMap);\n}","tryCatchPattern":"try {\n  Value v = periodicFn.apply(env, args);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Type mismatch on arg1\")) {\n    // drop arg1 or pass the annotated QUANT group instead\n  } else { throw e; }\n}","preventionTips":["Pass the quantifier as its annotated token-list capture group, never a string literal.","Remember arg1 is optional — omit it rather than passing a wrong-typed value.","Check group variable types after editing the surrounding pattern.","When calling programmatically, build arg1 from CoreMap annotations with TextAnnotation set."],"tags":["java","sutime","type-mismatch","quantifier"],"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"}