stanfordnlp/CoreNLP · error · RuntimeException
Cannot get field from
Error message
Cannot get field ${fieldName} from ${v} What it means
Thrown when the FIELD value function cannot read the requested field from an object via reflection; the underlying NoSuchFieldException or IllegalAccessException is wrapped in a RuntimeException. It means the field name in the expression does not exist on (or is not accessible from) the target object's class.
Solutions
- Verify the field name against the target class (or add the field).
- Make the field public, or access it via a public getter through a supported function instead of FIELD.
- Catch RuntimeException around expression evaluation and fall back to a null/typed value.
Example fix
// before Value v = FIELD($obj, "sentance"); // misspelled // after Value v = FIELD($obj, "sentence");
Defensive patterns
Strategy: try-catch
Validate before calling
try { Class.forName(obj.getClass().getName(), false, cl).getField(fieldName); } catch (NoSuchFieldException e) { /* invalid field name */ } Type guard
boolean hasField(Object o, String name) { try { o.getClass().getField(name); return true; } catch (NoSuchFieldException e) { return false; } } Try / catch
try { Value v = FIELD($obj, fieldName); } catch (RuntimeException e) { if (e.getMessage() != null && e.getMessage().startsWith("Cannot get field ")) { v = Expressions.createValue(null, null); } else throw e; } Prevention
- Keep field names in constants shared with the domain class
- Make reflected fields public or expose getters
- Re-run expression tests after renaming class fields
When it happens
Trigger: Evaluating a TokensRegex expression using FIELD(obj, "fieldName") where fieldName is misspelled or absent from the object's class, or the field is inaccessible (not public, wrong classloader).
Common situations: Typo'd field names in TokensRegex custom expressions; referencing fields of private classes or after refactoring renamed fields; accessing fields of wrapper/boxed objects mistakenly assumed to be the domain object.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Error getting field value for
- Invalid annotation key
- Unknown rule type:
- Error creating composite rule: no annotation field
- Annotation field cannot be null
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/68cbf5a2c38e2300.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ling/tokensregex/types/ValueFunctions.java:1345
if (elem instanceof Value) {
list2.add(((Value) elem).get());
} else {
list2.add(elem);
}
}
f.set(obj, list2);
}
} else {
f.set(obj, Arrays.asList(fieldValue.get()));
}
} else {
f.set(obj, fieldValue.get());
}
}
}
return Expressions.createValue(null, f.get(obj));
} catch (NoSuchFieldException | IllegalAccessException ex) {
throw new RuntimeException("Cannot get field " + fieldName + " from " + v, ex);
}
}
};
public static final ValueFunction LIST_VALUE_FUNCTION = new NamedValueFunction("LIST_VALUE") {
@Override
public String getParamDesc() {
return "List list,int index,[Object value]";
}
// First argument is List
// Second argument is index of element to select
// Third argument (optional) is value to assign list element
@Override
public boolean checkArgs(List<Value> in) {
if (in.size() != 2 && in.size() != 3) {
return false;
}View on GitHub (pinned to 1b7edd19c4)