{"record":{"id":"1ce4f0f1d5cf1e0b","repo":"stanfordnlp/CoreNLP","slug":"type-mismatch-on-arg0-cannot-apply-this-to-i","errorCode":null,"errorMessage":"Type mismatch on arg0: Cannot apply ${this} to ${in}","messagePattern":"Type mismatch on arg0: Cannot apply (.+?) to (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/types/ValueFunctions.java","lineNumber":918,"sourceCode":"        Object obj = cm.get(annotationFieldClass);\n        return Expressions.createValue(annotationFieldClass.getName(), obj);\n      } else if (cmv.get() instanceof List) {\n        List<CoreMap> cmList = (List<CoreMap>) cmv.get();\n        if (in.size() >= 3) {\n          Value v = in.get(2);\n          Object annotationObject = (v != null)? v.get():null;\n          for (CoreMap cm:cmList) {\n            cm.set(annotationFieldClass, annotationObject);\n          }\n        }\n        List<Object> list = new ArrayList<>();\n        Value res = new Expressions.PrimitiveValue(Expressions.TYPE_LIST, list);\n        for (CoreMap cm:cmList) {\n          list.add(cm.get(annotationFieldClass));\n        }\n        return res;\n      } else {\n        throw new IllegalArgumentException(\"Type mismatch on arg0: Cannot apply \" + this + \" to \" + in);\n      }\n    }\n  };\n\n  public static final ValueFunction GET_ANNOTATION_TAG_FUNCTION = new NamedValueFunction(\"GET_ANNOTATION_TAG\") {\n    @Override\n    public String getParamDesc() {\n      return \"CoreMap or List<CoreMap>,String tag\";\n    }\n\n    // First argument is what (CoreMap or List<CoreMap>) to tag\n    // Second argument is tag\n    @Override\n    public boolean checkArgs(List<Value> in) {\n      if (in.size() != 2) {\n        return false;\n      }\n      if (in.get(0) == null || in.get(0).get() == null) return true; // Allow for NULL","sourceCodeStart":900,"sourceCodeEnd":936,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/types/ValueFunctions.java#L900-L936","documentation":"GET_ANNOTATION_VALUE requires arg0 to be a CoreMap or a List<CoreMap>; when the first argument is any other type (String, Number, null-backed value, etc.) this IllegalArgumentException is thrown after the annotation field lookup succeeded.","triggerScenarios":"Calling GET_ANNOTATION_VALUE with a primitive/string as the first argument, or a Value whose get() is neither CoreMap nor List<CoreMap>, e.g. applying the function to a token's text instead of a CoreMap.","commonSituations":"Rules applying the annotation function to intermediate string values from earlier functions, pipeline stages producing non-CoreMap values, confusion between Tokens and CoreMaps.","solutions":["Ensure arg0 is a CoreMap (single annotation) or List<CoreMap> before applying the function.","Wrap the target in the appropriate value: use a CoreMap expression referencing the matched annotation.","Guard with instanceof checks on value.get() in custom code before invoking the function."],"exampleFix":"// before\nValue v = getFn.apply(env, Arrays.asList(Expressions.createValue(\"not-a-coremap\"), field));\n// after\nCoreMap cm = sentence;\nValue v = getFn.apply(env, Arrays.asList(new Expressions.PrimitiveValue<>(\"COREMAP\", cm), field));","handlingStrategy":"type-guard","validationCode":"Object v0 = args.get(0).get();\nif (!(v0 instanceof CoreMap || v0 instanceof List)) throw new IllegalArgumentException(\"arg0 must be CoreMap or List<CoreMap>\");","typeGuard":"boolean isCoreMapValue(Value v) {\n    Object o = v != null ? v.get() : null;\n    return o instanceof CoreMap || o instanceof List;\n}","tryCatchPattern":"try {\n    v = getFn.apply(env, args);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Type mismatch on arg0\")) {\n        v = null; // non-CoreMap input\n    } else throw e;\n}","preventionTips":["Apply annotation functions only to CoreMap-bearing values","Reference matched annotations ($0, $1) rather than extracted strings","Inspect intermediate value types when chaining functions"],"tags":["tokensregex","type-mismatch","coremap"],"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"}