{"record":{"id":"4cd1f6cd17c08a3e","repo":"stanfordnlp/CoreNLP","slug":"core-corelabel-initfromstrings-can-t-handle-val","errorCode":null,"errorMessage":"CORE: CoreLabel.initFromStrings: Can't handle <valueClass> (key <key>)","messagePattern":"CORE: CoreLabel\\.initFromStrings: Can't handle <valueClass> \\(key <key>\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/CoreLabel.java","lineNumber":206,"sourceCode":"          throw new UnsupportedOperationException(\"Unknown key \" + key);\n        }\n      } else {\n        try {\n          Class<?> valueClass = AnnotationLookup.getValueType(coreKeyClass);\n          if(valueClass.equals(String.class)) {\n            this.set(coreKeyClass, values[i]);\n          } else if(valueClass == Integer.class) {\n            this.set(coreKeyClass, Integer.parseInt(values[i]));\n          } else if(valueClass == Double.class) {\n            this.set(coreKeyClass, Double.parseDouble(values[i]));\n          } else if(valueClass == Long.class) {\n            this.set(coreKeyClass, Long.parseLong(values[i]));\n          } else if (valueClass == Boolean.class) {\n            this.set(coreKeyClass, Boolean.parseBoolean(values[i]));\n          } else if (coreKeyClass == CoreAnnotations.CoNLLUFeats.class) {\n            this.set(coreKeyClass, new CoNLLUFeatures(values[i]));\n          } else {\n            throw new UnsupportedOperationException(\"CORE: CoreLabel.initFromStrings: \" +\n                                                    \"Can't handle \" + valueClass + \" (key \" + key + \")\");\n          }\n        } catch (NumberFormatException e) {\n          // unexpected value type\n          throw new UnsupportedOperationException(\"CORE: CoreLabel.initFromStrings: \"\n              + \"Bad type for \" + key\n              + \". Value was: \" + value\n              + \"; expected \"+AnnotationLookup.getValueType(coreKeyClass), e);\n        }\n      }\n    }\n  }\n\n  @SuppressWarnings(\"rawtypes\")\n  public static Class[] parseStringKeys(String[] keys) {\n    Class[] classes = new Class[keys.length];\n    for (int i = 0; i < keys.length; i++) {\n      String key = keys[i];","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/CoreLabel.java#L188-L224","documentation":"CoreLabel.initFromStrings throws UnsupportedOperationException when the key's declared value type is not one of the handled types (String, Integer, Long, Double, Boolean, or the special CoNLLUFeats case). The value string cannot be coerced into the annotation's type.","triggerScenarios":"Providing a key whose AnnotationLookup value type is e.g. a List or a Class (like CoreAnnotations.CoNLLUFeatures or other complex annotations) with a plain string value that initFromStrings has no conversion branch for.","commonSituations":"Feeding serialized labels containing complex annotations (lists of tokens, sentences, or machine-generated value types) back through the string-based CoreLabel constructor; custom annotations registered with non-scalar types.","solutions":["Only pass string keys whose value type is a scalar (String/Integer/Long/Double/Boolean) through the string constructor.","Set complex annotations directly with label.set(CoreAnnotations.X.class, value) instead of via initFromStrings.","Convert the complex value to a supported scalar representation before constructing.","Check AnnotationLookup.getValueType(key) beforehand to know which types the constructor can handle."],"exampleFix":"// before\nnew CoreLabel(new String[]{\"Tokens\"}, new String[]{\"the|the\"}); // value type is List, can't handle\n// after\nCoreLabel l = new CoreLabel(new String[]{\"Text\"}, new String[]{\"the\"});\nl.set(CoreAnnotations.TokensAnnotation.class, tokenList);","handlingStrategy":"validation","validationCode":"Class<?> vc = AnnotationLookup.getValueType(AnnotationLookup.toCoreKey(key));\nboolean scalar = vc.equals(String.class) || vc.equals(Integer.class)\n    || vc.equals(Long.class) || vc.equals(Double.class) || vc.equals(Boolean.class);\nif (!scalar) {\n  throw new IllegalArgumentException(\"Key \" + key + \" has non-scalar type \" + vc + \"; set it via label.set() instead\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  return new CoreLabel(keys, values);\n} catch (UnsupportedOperationException e) {\n  if (e.getMessage().contains(\"Can't handle\")) {\n    // fall back to setting complex annotations individually\n  }\n  throw e;\n}","preventionTips":["Check AnnotationLookup.getValueType before passing a key through the string constructor.","Set complex-typed annotations directly with CoreLabel.set instead of string-based construction.","Restrict serialized label formats to scalar annotation types."],"tags":["type-mismatch","corelabel","annotations","value-type"],"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"}