stanfordnlp/CoreNLP · error · IllegalArgumentException
Unsupported dependency type:
Error message
Unsupported dependency type:
What it means
Sentence's internal call to impl.dependencies(mode) hits the default branch of a switch over GrammaticalStructure.DependencyMode when the mode value is unrecognized, throwing IllegalArgumentException with 'Unsupported dependency type: ' + mode. In practice the three enum cases (BASIC, ENHANCED, ENHANCED_PLUS_PLUS) cover all values, so this is a defensive invariant guard reached only if a new enum constant is added without updating this switch.
Solutions
- Use only DependencyMode.BASIC, ENHANCED, or ENHANCED_PLUS_PLUS
- Upgrade/align CoreNLP jars so the enum and Sentence come from the same version
- Check for library bug if it occurs with stock API and report to CoreNLP maintainers
Example fix
// before
SemanticGraph g = sentence.dependencies(GrammaticalStructure.DependencyMode.ENHANCED_PLUS_PLUS);
// after
if (mode != BASIC && mode != ENHANCED && mode != ENHANCED_PLUS_PLUS) {
mode = GrammaticalStructure.DependencyMode.BASIC;
}
SemanticGraph g = sentence.dependencies(mode); Defensive patterns
Strategy: validation
Validate before calling
// restrict mode to known values
if (mode != GrammaticalStructure.DependencyMode.BASIC
&& mode != GrammaticalStructure.DependencyMode.ENHANCED
&& mode != GrammaticalStructure.DependencyMode.ENHANCED_PLUS_PLUS) {
mode = GrammaticalStructure.DependencyMode.BASIC;
} Type guard
boolean isValidDependencyMode(GrammaticalStructure.DependencyMode m) {
return m == BASIC || m == ENHANCED || m == ENHANCED_PLUS_PLUS;
} Try / catch
try {
SemanticGraph g = sentence.dependencies(mode);
} catch (IllegalArgumentException e) {
SemanticGraph g = sentence.dependencies(GrammaticalStructure.DependencyMode.BASIC);
} Prevention
- Use only the three documented DependencyMode constants
- Keep all CoreNLP jars at one version
- Pin CoreNLP version in your build to avoid enum drift
When it happens
Trigger: Calling Sentence.dependencies(), governors(), governor(), incomingDependencyLabel(s), or dependencyGraph() with a dependency mode that the underlying impl does not map; mainly occurs after custom extensions or a version mismatch introducing a new DependencyMode constant.
Common situations: Upgrading CoreNLP where a new DependencyMode was added but Sentence's switch not updated; reflection or serialization restoring a stale/unexpected mode value.
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
- Unknown sentiment class:
- Shouldn't happen:
- Error reading saved links
- RuntimeIOException wrapping IOException
- Error creating data exporter
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/3d751b7acb5161e2.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/simple/Sentence.java:658
}
/** @see Sentence#parse(java.util.Properties) */
public Tree parse() {
return parse(this.defaultProps);
}
/** An internal helper to get the dependency tree of the given type. */
private CoreNLPProtos.DependencyGraph dependencies(SemanticGraphFactory.Mode mode) {
switch (mode) {
case BASIC:
return impl.getBasicDependencies();
case ENHANCED:
return impl.getEnhancedDependencies();
case ENHANCED_PLUS_PLUS:
return impl.getEnhancedPlusPlusDependencies();
default:
throw new IllegalArgumentException("Unsupported dependency type: " + mode);
}
}
/**
* Returns the governor of the given index, according to the passed dependency type.
* The root has index -1.
*
* @param props The properties to use in the parser annotator.
* @param index The index of the dependent word ZERO INDEXED. That is, the first word of the sentence
* is index 0, not 1 as it would be in the {@link edu.stanford.nlp.semgraph.SemanticGraph} framework.
* @param mode The type of dependency to use (e.g., basic, collapsed, collapsed cc processed).
* @return The index of the governor, if one exists. A value of -1 indicates the root node.
*/
public Optional<Integer> governor(Properties props, int index, SemanticGraphFactory.Mode mode) {
document.runDepparse(props);
for (CoreNLPProtos.DependencyGraph.Edge edge : dependencies(mode).getEdgeList()) {
if (edge.getTarget() - 1 == index) {
return Optional.of(edge.getSource() - 1);View on GitHub (pinned to 1b7edd19c4)