stanfordnlp/CoreNLP · error · IllegalArgumentException
Invalid feature name '
Error message
Invalid feature name '
What it means
TregexPoweredTreebankParserParams.addFeature looks up the requested feature name in the static 'annotations' registry; unknown names throw IllegalArgumentException('Invalid feature name ...'). Only pre-registered annotation feature names (defined in the annotations map) may be added via -annotator style options.
Solutions
- Use a feature name defined in TregexPoweredTreebankParserParams.annotations (check the source for the exact list).
- Fix spelling/case of the feature name in your options file.
- Call compileAnnotations() before addFeature() if wiring the params programmatically.
- Verify the feature exists in your library version; upgrade/downgrade if the feature was added later.
Example fix
// before
params.setOptionFlag(new String[]{"-annotator", "SemanticHead"}, 0);
// after (use a registered feature name)
params.setOptionFlag(new String[]{"-annotator", "HeadOfNp"}, 0); Defensive patterns
Strategy: validation
Validate before calling
if (!TregexPoweredTreebankParserParams.annotations.containsKey(featureName))
throw new IllegalArgumentException("Unknown annotation feature: " + featureName); Try / catch
try {
params.addFeature(name);
} catch (IllegalArgumentException e) {
System.err.println("Invalid feature '" + name + "'; check the annotations registry in TregexPoweredTreebankParserParams");
} Prevention
- Copy feature names from the annotations map in the source of your version.
- Call compileAnnotations() before addFeature() when using the API programmatically.
- Keep options files and library versions aligned.
When it happens
Trigger: Passing an unrecognized feature name to TregexPoweredTreebankParserParams (e.g., via the -annotator option or annotate.addFeature API) that has no entry in the annotations map, or before compileAnnotations was called (which then throws the related RuntimeException).
Common situations: Typos in feature names in training configs, copying feature names from a different parser version where the registry changed, or calling addFeature before compileAnnotations().
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- FrenchLexer: Invalid option value in constructor: :
- Invalid value for -distanceBin:
- Not a valid dashes style:
- : Invalid options key in constructor: %n
- Unknown clique: " + clique
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/8277784500ba4bb6.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/lexparser/TregexPoweredTreebankParserParams.java:141
Pair<TregexPattern, Function<TregexMatcher, String>> behavior =
new Pair<>(compiled, annotation.getValue().second());
annotationPatterns.put(annotation.getKey(), behavior);
}
}
/**
* Enable an annotation feature. If the provided feature has already
* been enabled, this method does nothing.
*
* @param featureName
* @throws java.lang.IllegalArgumentException If the provided feature
* name is unknown (i.e., if there is no entry in the
* {@link #annotations} collection with the same name)
*/
protected void addFeature(String featureName) {
if (!annotations.containsKey(featureName))
throw new IllegalArgumentException("Invalid feature name '" + featureName + "'");
if (!annotationPatterns.containsKey(featureName))
throw new RuntimeException("Compiled patterns out of sync with annotations data structure;" +
"did you call compileAnnotations?");
features.add(featureName);
}
/**
* Disable a feature. If the feature was never enabled, this method
* returns without error.
*
* @param featureName
*/
protected void removeFeature(String featureName) {
features.remove(featureName);
}
/**View on GitHub (pinned to 1b7edd19c4)