{"record":{"id":"9fa4f35796e40883","repo":"stanfordnlp/CoreNLP","slug":"core-corelabel-initfromstrings-can-t-handle-val-9fa4f3","errorCode":null,"errorMessage":"CORE: CoreLabel.initFromStrings: Can't handle <valueClass> (key <coreKeyClass>)","messagePattern":"CORE: CoreLabel\\.initFromStrings: Can't handle <valueClass> \\(key <coreKeyClass>\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/CoreLabel.java","lineNumber":259,"sourceCode":"    for (int i = 0; i < keys.length; i++) {\n      Class coreKeyClass = keys[i];\n      String value = values[i];\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 \" + coreKeyClass + \")\");\n        }\n      } catch (NumberFormatException e) {\n        // unexpected value type\n        throw new UnsupportedOperationException(\"CORE: CoreLabel.initFromStrings: \"\n            + \"Bad type for \" + coreKeyClass.getSimpleName()\n            + \". Value was: \" + value\n            + \"; expected \"+AnnotationLookup.getValueType(coreKeyClass), e);\n      }\n    }\n  }\n\n  private static class CoreLabelFactory implements LabelFactory {\n\n    @Override\n    public Label newLabel(String labelStr) {\n      CoreLabel label = new CoreLabel();\n      label.setValue(labelStr);","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/CoreLabel.java#L241-L277","documentation":"In initFromStrings, each value string is parsed according to the target annotation's value type (String, Integer, Long, Boolean, CoNLLUFeatures). If AnnotationLookup reports a value class for the key that this branch does not handle (e.g. Double or any other non-supported type), CoreLabel throws this UnsupportedOperationException. It is an internal gap: the key is known but its value type cannot be built from a String here.","triggerScenarios":"new CoreLabel(String[] keys, String[] values) where a key's AnnotationLookup value type is a class not covered by the if/else chain (not String, Integer, Long, Boolean, or CoreAnnotations.CoNLLUFeats), e.g. passing a key whose value type is Double.","commonSituations":"Using annotation keys that store non-string, non-integer types (like Double-valued scores) through the generic string constructor; library-version changes that add new value types not handled in older CoreLabel code paths.","solutions":["Avoid the string-array constructor for that key; construct the CoreLabel and call label.set(MyAnnotation.class, parsedValue) directly with the correctly typed value.","Check AnnotationLookup.getValueType(coreKeyClass) for the key and ensure your value string fits a supported type (String/Integer/Long/Boolean/CoNLLUFeatures).","Upgrade Stanford CoreNLP if the key was recently added, since newer versions may handle the value type in initFromStrings."],"exampleFix":"// before\nnew CoreLabel(new String[]{\"myScoreKey\"}, new String[]{\"0.75\"}); // valueClass Double not handled\n// after\nCoreLabel label = new CoreLabel();\nlabel.set(MyScoreAnnotation.class, Double.parseDouble(\"0.75\"));","handlingStrategy":"type-guard","validationCode":"// java\nClass<?> valueClass = edu.stanford.nlp.ling.AnnotationLookup.getValueType(\n    edu.stanford.nlp.ling.AnnotationLookup.toCoreKey(key));\nboolean supported = valueClass == String.class || valueClass == Integer.class\n    || valueClass == Long.class || valueClass == Boolean.class\n    || valueClass == edu.stanford.nlp.ling.CoreAnnotations.CoNLLUFeats.class;\nif (!supported) {\n  // set the typed value directly instead of using the string constructor\n}","typeGuard":"// java\nstatic boolean isStringConstructible(Class<? extends java.util.Map.Key<?>> coreKey) {\n  Class<?> vc = AnnotationLookup.getValueType(coreKey);\n  return vc == String.class || vc == Integer.class || vc == Long.class\n      || vc == Boolean.class || vc == CoreAnnotations.CoNLLUFeats.class;\n}","tryCatchPattern":"// java\ntry {\n  label = new CoreLabel(keys, values);\n} catch (UnsupportedOperationException e) {\n  if (e.getMessage().contains(\"Can't handle\")) {\n    // fall back to per-key label.set(Class, typedValue) construction\n  } else throw e;\n}","preventionTips":["For annotations with exotic value types, always use label.set(KeyClass, typedValue) instead of the string constructor.","Consult AnnotationLookup.getValueType before feeding a key into the string constructor.","Pin and test against a specific CoreNLP version so value-type handling matches your expectations."],"tags":["nlp","corelabel","type-unsupported","annotation"],"backgroundTag":"unsupported-dtype","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"}