stanfordnlp/CoreNLP · error · UnsupportedOperationException
CORE: CoreLabel.initFromStrings: Can't handle <valueClass> (
Error message
CORE: CoreLabel.initFromStrings: Can't handle <valueClass> (key <coreKeyClass>)
What it means
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.
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.
Example fix
// before
new CoreLabel(new String[]{"myScoreKey"}, new String[]{"0.75"}); // valueClass Double not handled
// after
CoreLabel label = new CoreLabel();
label.set(MyScoreAnnotation.class, Double.parseDouble("0.75")); Defensive patterns
Strategy: type-guard
Validate before calling
// java
Class<?> valueClass = edu.stanford.nlp.ling.AnnotationLookup.getValueType(
edu.stanford.nlp.ling.AnnotationLookup.toCoreKey(key));
boolean supported = valueClass == String.class || valueClass == Integer.class
|| valueClass == Long.class || valueClass == Boolean.class
|| valueClass == edu.stanford.nlp.ling.CoreAnnotations.CoNLLUFeats.class;
if (!supported) {
// set the typed value directly instead of using the string constructor
} Type guard
// java
static boolean isStringConstructible(Class<? extends java.util.Map.Key<?>> coreKey) {
Class<?> vc = AnnotationLookup.getValueType(coreKey);
return vc == String.class || vc == Integer.class || vc == Long.class
|| vc == Boolean.class || vc == CoreAnnotations.CoNLLUFeats.class;
} Try / catch
// java
try {
label = new CoreLabel(keys, values);
} catch (UnsupportedOperationException e) {
if (e.getMessage().contains("Can't handle")) {
// fall back to per-key label.set(Class, typedValue) construction
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- CORE: CoreLabel.initFromStrings: Bad type for <coreKeyClass.
- This code branch left blank because we do not understand wha
- Cannot set from string
- Can only set spans on trees which use CoreLabel
- Expected leaves to be CoreLabels
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/9fa4f35796e40883.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ling/CoreLabel.java:259
for (int i = 0; i < keys.length; i++) {
Class coreKeyClass = keys[i];
String value = values[i];
try {
Class<?> valueClass = AnnotationLookup.getValueType(coreKeyClass);
if (valueClass.equals(String.class)) {
this.set(coreKeyClass, values[i]);
} else if (valueClass == Integer.class) {
this.set(coreKeyClass, Integer.parseInt(values[i]));
} else if (valueClass == Double.class) {
this.set(coreKeyClass, Double.parseDouble(values[i]));
} else if (valueClass == Long.class) {
this.set(coreKeyClass, Long.parseLong(values[i]));
} else if (valueClass == Boolean.class) {
this.set(coreKeyClass, Boolean.parseBoolean(values[i]));
} else if (coreKeyClass == CoreAnnotations.CoNLLUFeats.class) {
this.set(coreKeyClass, new CoNLLUFeatures(values[i]));
} else {
throw new UnsupportedOperationException("CORE: CoreLabel.initFromStrings: " +
"Can't handle " + valueClass + " (key " + coreKeyClass + ")");
}
} catch (NumberFormatException e) {
// unexpected value type
throw new UnsupportedOperationException("CORE: CoreLabel.initFromStrings: "
+ "Bad type for " + coreKeyClass.getSimpleName()
+ ". Value was: " + value
+ "; expected "+AnnotationLookup.getValueType(coreKeyClass), e);
}
}
}
private static class CoreLabelFactory implements LabelFactory {
@Override
public Label newLabel(String labelStr) {
CoreLabel label = new CoreLabel();
label.setValue(labelStr);View on GitHub (pinned to 1b7edd19c4)