stanfordnlp/CoreNLP · error · IllegalArgumentException
Unknown mode
Error message
Unknown mode
What it means
ArrayStringFilter.test() switches over the filter's Mode enum; if mode is not one of the three known values (EXACT, PREFIX, CASE_INSENSITIVE), the default branch throws IllegalArgumentException('Unknown mode ' + mode). This guards against a Mode enum that was extended in a newer library version while the switch was not updated.
Solutions
- Upgrade/downgrade so the ArrayStringFilter version matches the one that created the filter, ensuring the Mode constant exists in both.
- Ensure the filter is only constructed with Mode.EXACT, Mode.PREFIX, or Mode.CASE_INSENSITIVE.
- If you control the enum, add a case for the new constant in the switch before using the filter.
Example fix
// before Mode mode = MyCustomModes.SUFFIX; // not handled by ArrayStringFilter ArrayStringFilter f = new ArrayStringFilter(mode, "x"); // after ArrayStringFilter f = new ArrayStringFilter(ArrayStringFilter.Mode.PREFIX, "x");
Defensive patterns
Strategy: type-guard
Validate before calling
if (mode != ArrayStringFilter.Mode.EXACT && mode != ArrayStringFilter.Mode.PREFIX && mode != ArrayStringFilter.Mode.CASE_INSENSITIVE) {
throw new IllegalArgumentException("unsupported mode: " + mode);
} Type guard
boolean isSupportedMode(ArrayStringFilter.Mode m) {
return m == ArrayStringFilter.Mode.EXACT || m == ArrayStringFilter.Mode.PREFIX || m == ArrayStringFilter.Mode.CASE_INSENSITIVE;
} Try / catch
try {
boolean hit = filter.test(input);
} catch (IllegalArgumentException e) {
// recreate the filter with a known Mode and retry
} Prevention
- Keep serialization/deserialization of filters on the same library version on both sides.
- Construct filters only with constants from ArrayStringFilter.Mode, never via reflection.
- If you extend Mode, update the test() switch in the same change.
When it happens
Trigger: Calling test() on an ArrayStringFilter whose mode is a newly added or unknown Mode constant not handled by this switch, e.g. a filter constructed in a different library version or via reflection/deserialization with an unexpected mode.
Common situations: Mixing library versions (serializing/deserializing filters across versions where Mode has extra constants); extending the Mode enum locally without updating test(); Java enum deserialization producing a constant unknown to the installed version.
Related errors
- Arabic does not support feature type: " + feat.toString()
- Don't know anything about tagset
- entitySubclassify: unknown style:
- ERROR: unknown dependency type
- is not a legal LogPrior.
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/bf1b31b2a00a927a.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/util/ArrayStringFilter.java:66
case PREFIX:
if (input == null) {
return false;
}
for (int i = 0; i < length; ++i) {
if (input.startsWith(words[i])) {
return true;
}
}
return false;
case CASE_INSENSITIVE:
for (int i = 0; i < length; ++i) {
if (words[i].equalsIgnoreCase(input)) {
return true;
}
}
return false;
default:
throw new IllegalArgumentException("Unknown mode " + mode);
}
}
@Override
public String toString() {
return mode.toString() + ':' + StringUtils.join(words, ",");
}
@Override
public int hashCode() {
int result = 1;
for (String word : words) {
result += word.hashCode();
}
return result;
}
@OverrideView on GitHub (pinned to 1b7edd19c4)