stanfordnlp/CoreNLP · error · RuntimeException
Unknown field for type , trying to set to
Error message
Unknown field ${s} for type ${typeName}, trying to set to ${v} What it means
When evaluating a CompositeValue typed as a CLASS, the library instantiates the class and sets each attribute via reflection. If the attribute name does not correspond to any public Field on the target class, getField throws NoSuchFieldException, which is rethrown as this RuntimeException. It means the composite literal names a key the Java type does not have.
Solutions
- Fix the attribute name in the rule/expression to match an existing public field of the class.
- Inspect the target class (or its public API) to see which fields are settable; note only public fields are found via getField.
- If the field legitimately changed name in a newer CoreNLP version, update the rule or pin the library version.
- Wrap evaluation in a try-catch for RuntimeException if the rule may reference optional fields, and drop unknown keys before evaluation.
Example fix
// before
(Entity) { nane: $name } // typo: no field 'nane'
// after
(Entity) { name: $name } // matches public field Entity.name Defensive patterns
Strategy: validation
Validate before calling
for (String key : composite.getAttributeNames()) {
try { targetClass.getField(key); }
catch (NoSuchFieldException e) { throw new IllegalStateException("Rule references unknown field: " + key); }
} Type guard
static boolean hasPublicField(Class<?> c, String name) {
try { return c.getField(name) != null; } catch (NoSuchFieldException e) { return false; }
} Try / catch
try { Value v = composite.evaluate(env, args); }
catch (RuntimeException ex) {
if (ex.getMessage().startsWith("Unknown field")) {
log.error("Rule field mismatch: " + ex.getMessage(), ex);
}
throw ex;
} Prevention
- Keep field names in rules in sync with the target class's public fields
- Use fully qualified types and consult the class source when authoring rules
- Pin CoreNLP version and re-test rules after upgrades
When it happens
Trigger: Evaluating a composite expression like (CLASS) { key: value } where `key` is not a declared public field of the named class; typos in attribute names in TokensRegex rule composite literals; renaming a field in the target class without updating the rule.
Common situations: TokensRegex rules constructing annotation-like objects or custom result types where the rule author misspells a field or assumes a field exists that was removed/renamed in a CoreNLP version change.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Incompatible type for type , trying to set to
- Invalid node pattern class: for variable
- Invalid node pattern variable class: for variable
- Invalid sequence pattern variable class:
- Unexpected class in list while looking up word () in…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/6fa340b0560c2346.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ling/tokensregex/types/Expressions.java:1277
if (typeValue != null) {
// Check if variable points to a class
// If so, then try to instantiate a new instance of the class
if (TYPE_CLASS.equals(typeValue.getType())) {
// Variable maps to a java class
Class c = (Class) typeValue.get();
try {
Object obj = c.newInstance();
// for any field other than the "type", set the value of the field
// of the created object to the specified value
for (String s:cv.value.keySet()) {
if (!"type".equals(s)) {
Value v = cv.value.get(s).evaluate(env, args);
try {
Field f = c.getField(s);
Object objVal = toCompatibleObject(f, v.get());
f.set(obj, objVal);
} catch (NoSuchFieldException ex){
throw new RuntimeException("Unknown field " + s + " for type " + typeName + ", trying to set to " + v, ex);
} catch (IllegalArgumentException ex){
throw new RuntimeException("Incompatible type " + s + " for type " + typeName + ", trying to set to " + v, ex);
}
}
}
return new PrimitiveValue<>(typeName, obj);
} catch (InstantiationException | IllegalAccessException ex) {
throw new RuntimeException("Cannot instantiate " + c, ex);
}
} else if (typeValue.get() != null){
// When evaluated, variable does not explicitly map to "CLASS"
// See if we can convert this CompositeValue into appropriate object
// by calling "create(CompositeValue cv)"
Class c = typeValue.get().getClass();
try {
Method m = c.getMethod("create", CompositeValue.class);
CompositeValue evaluatedCv = cv.evaluateNoTypeConversion(env, args);
try {View on GitHub (pinned to 1b7edd19c4)