stanfordnlp/CoreNLP · error · RuntimeException
Unknown general relation <shortName>
Error message
Unknown general relation <shortName>
What it means
readResolve() reconstructs the canonical GrammaticalRelation instance after deserialization by matching the relation's shortName against the known constants for the GENERAL language case (GOVERNOR, DEPENDENT, ROOT, KILL). If the shortName matches none of them, the relation cannot be resolved and this RuntimeException is thrown — typically the result of deserializing a relation from an incompatible library version or corrupted stream.
Solutions
- Regenerate the serialized data with the same CoreNLP version that will deserialize it
- Check the shortName in the stream/data for typos and correct it to a valid GENERAL relation (GOVERNOR, DEPENDENT, ROOT, KILL)
- Upgrade or downgrade the CoreNLP dependency so both writer and reader use compatible relation definitions
- Instead of Java serialization, persist relations as strings and rebuild them via GrammaticalRelations.valueOf/fromString
Example fix
// before
ObjectInputStream in = new ObjectInputStream(new FileInputStream("rels-old.ser")); // written by CoreNLP 1.3
// after
// re-serialize with the current CoreNLP version, or:
GrammaticalRelation rel = GrammaticalRelations.valueOf(Language.General, "DEPENDENT"); Defensive patterns
Strategy: try-catch
Validate before calling
Set<String> valid = Set.of("GOVERNOR","DEPENDENT","ROOT","KILL");
if (!valid.contains(shortName)) throw new IllegalArgumentException("Cannot resolve GENERAL relation: " + shortName); Try / catch
try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(f))) {
GrammaticalRelation r = (GrammaticalRelation) in.readObject();
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Unknown general relation")) {
// rebuild relation by name or re-serialize data with matching version
} else throw e;
} Prevention
- Serialize and deserialize with the same CoreNLP version
- Persist relations as name strings instead of Java serialization
- Validate shortNames before serializing custom data
- Keep model artifacts versioned alongside the library
When it happens
Trigger: Deserializing a serialized GrammaticalRelation whose language is GENERAL and whose shortName is not GOVERNOR/DEPENDENT/ROOT/KILL; reading a serialization produced by a different CoreNLP version where relation names changed.
Common situations: Reading old serialized models/objects after upgrading Stanford CoreNLP; deserializing hand-crafted or corrupted relation objects; serializing relations across JVMs with mismatched class versions.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Couldn't load {file}
- ILLEGAL VALUE IN SERIALIZED SYMBOL
- Invalid class in file:
- Failed to find node " + ie.source + "-" + ie.sourceCopy
- Failed to find node " + ie.target + "-" + ie.targetCopy
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/f70b27a6dcab47f4.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/trees/GrammaticalRelation.java:559
*
* TODO: there are a bunch of things wrong with this. For one
* thing, it's crazy slow, since it goes through all the existing
* relations in an array. For another, it would be cleaner to have
* subclasses for the English and Chinese relations
*/
protected Object readResolve() throws ObjectStreamException {
switch (language) {
case Any: {
if (shortName.equals(GOVERNOR.shortName)) {
return GOVERNOR;
} else if (shortName.equals(DEPENDENT.shortName)) {
return DEPENDENT;
} else if (shortName.equals(ROOT.shortName)) {
return ROOT;
} else if (shortName.equals(KILL.shortName)) {
return KILL;
} else {
throw new RuntimeException("Unknown general relation " + shortName);
}
}
case English: {
GrammaticalRelation rel = EnglishGrammaticalRelations.valueOf(toString());
if (rel == null) {
switch (shortName) {
case "conj":
return EnglishGrammaticalRelations.getConj(specific);
case "prep":
return EnglishGrammaticalRelations.getPrep(specific);
case "prepc":
return EnglishGrammaticalRelations.getPrepC(specific);
default:
// TODO: we need to figure out what to do with relations
// which were serialized and then deprecated. Perhaps there
// is a good way to make them singletons
return this;
//throw new RuntimeException("Unknown English relation " + this);View on GitHub (pinned to 1b7edd19c4)