stanfordnlp/CoreNLP · error · RuntimeException
Unknown language
Error message
Unknown language <language>
What it means
readResolve() switches on the GrammaticalRelation's language to find the canonical instance for that language. The switch only handles the languages the library knows; any other value falls into the default branch and throws this RuntimeException, meaning the deserialized relation carries a language the code cannot resolve.
Solutions
- Ensure the relation's language is one supported by this CoreNLP version (e.g. English, Chinese, UniversalEnglish...) before serializing
- Re-serialize with matching CoreNLP versions on both ends
- Inspect the stream for corruption if language is unexpectedly null/garbage
- Use the string-based GrammaticalRelations.valueOf(language, name) API with an explicit valid language instead of raw serialization
Example fix
// before GrammaticalRelation r = new GrammaticalRelation(someForeignLanguage, "dep", ...); // then serialized // after GrammaticalRelation r = new GrammaticalRelation(Language.English, "dep", ...);
Defensive patterns
Strategy: try-catch
Validate before calling
if (language == null || !supportedLanguages.contains(language)) {
throw new IllegalArgumentException("Unsupported language for GrammaticalRelation: " + language);
} Try / catch
try {
GrammaticalRelation r = (GrammaticalRelation) in.readObject();
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Unknown language")) {
// rebuild relation with an explicitly supported Language constant
} else throw e;
} Prevention
- Only use Language constants from the CoreNLP version in use
- Avoid hand-serializing GrammaticalRelation objects
- Pin CoreNLP versions across services sharing serialized data
- Convert relations to (language, name) string pairs for storage
When it happens
Trigger: Deserializing a GrammaticalRelation whose language field is null or a value outside the handled enum cases (e.g. a Language constant from a different library version, or a stream corrupted so the field is wrong).
Common situations: Cross-version deserialization where the Language enum gained/lost constants; manually constructing/serializing a relation with an unhandled language; classloader conflicts yielding a mismatched Language enum.
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
- CoreMap is actually a CoreLabel
- Could not open temporary feature index file for reading.
- Could not read string buffer fully!
- Could not save model to stream!
- ERROR: Incorrect format for the serialized coref graph
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/97fc16946f2e411c.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/trees/GrammaticalRelation.java:618
case "nmod":
return UniversalEnglishGrammaticalRelations.getNmod(specific);
case "acl":
return UniversalEnglishGrammaticalRelations.getAcl(specific);
case "advcl":
return UniversalEnglishGrammaticalRelations.getAdvcl(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);
}
} else {
return rel;
}
default: {
throw new RuntimeException("Unknown language " + language);
}
}
}
/**
* Returns the parent of this {@code GrammaticalRelation}.
*/
public GrammaticalRelation getParent() {
return parent;
}
public static void main(String[] args) {
final String[] names = {"dep", "pred", "prep_to","rcmod"};
for (String name : names) {
GrammaticalRelation reln = valueOf(Language.English, name);
System.out.println("Data for GrammaticalRelation loaded as valueOf(\"" + name + "\"):");
System.out.println("\tShort name: " + reln.getShortName());
System.out.println("\tLong name: " + reln.getLongName());View on GitHub (pinned to 1b7edd19c4)