stanfordnlp/CoreNLP · error · IllegalArgumentException
SpanishLexer: Invalid option value in constructor
Error message
SpanishLexer: Invalid option value in constructor: ${key}: ${value} What it means
This is the fall-through error in SpanishLexer's option-handling switch: any 'untokenizable' value outside the recognized UntokenizableOptions names (e.g. noneDelete, firstKeep, allKeep, etc.) is rejected. The message includes both the option key and the offending value, distinguishing it from the separate unknown-key error.
Solutions
- Use one of the exact UntokenizableOptions values: noneDelete, noneKeep, noneThrow, firstDelete, firstKeep, firstThrow, allDelete, allKeep, allThrow (as defined in the switch).
- Verify the untokenizable value casing — the switch matches exact strings like 'allKeep', not all-lowercase.
- Normalize/validate the option string before constructing the lexer.
- Catch IllegalArgumentException during lexer construction to report the bad key/value pair to users.
Example fix
// before new SpanishLexer(reader, "untokenizable=keep-all"); // after new SpanishLexer(reader, "untokenizable=allKeep");
Defensive patterns
Strategy: validation
Validate before calling
java.util.Set<String> valid = java.util.Set.of("noneDelete","noneKeep","noneThrow",
"firstDelete","firstKeep","firstThrow","allDelete","allKeep","allThrow");
String v = value.trim();
if (!valid.contains(v)) throw new IllegalArgumentException("Bad untokenizable option: " + v); Type guard
static boolean isValidUntokenizable(String value) {
if (value == null) return false;
switch (value.trim()) {
case "noneDelete": case "noneKeep": case "noneThrow":
case "firstDelete": case "firstKeep": case "firstThrow":
case "allDelete": case "allKeep": case "allThrow":
return true;
default:
return false;
}
} Try / catch
try {
lexer = new SpanishLexer(reader, options);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("Invalid option value in constructor")) {
// log key/value, apply safe default
lexer = new SpanishLexer(reader, options.replaceAll("untokenizable=[^,]*", "untokenizable=noneDelete"));
} else { throw e; }
} Prevention
- Use the exact camelCase option values (e.g. allKeep) — the switch is case-sensitive.
- Parse the options string into key/value pairs before passing it to the lexer.
- Add a unit test constructing the lexer with every documented option value.
- Log key and value when construction fails to speed up config debugging.
When it happens
Trigger: Constructing SpanishLexer with 'untokenizable=<badValue>', e.g. 'untokenizable=keep-all', 'untokenizable=none', an empty value, or a value with unexpected casing/whitespace beyond trim.
Common situations: Config copied from PTBTokenizer docs but with altered enum names; typos in properties files; programmatic option string built by concatenation producing empty or doubled values; version drift where an option alias was removed.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Not a valid ellipses style
- Not a valid dashes style
- Not a valid ellipses style:
- TokenizerAnnotator: unknown tokenize.class property
- TokenizerAnnotator: unknown tokenize.language property
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/2a9fd2f93c26dec4.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/international/spanish/process/SpanishLexer.java:14183
untokenizable = UntokenizableOptions.NONE_DELETE;
break;
case "firstDelete":
untokenizable = UntokenizableOptions.FIRST_DELETE;
break;
case "allDelete":
untokenizable = UntokenizableOptions.ALL_DELETE;
break;
case "noneKeep":
untokenizable = UntokenizableOptions.NONE_KEEP;
break;
case "firstKeep":
untokenizable = UntokenizableOptions.FIRST_KEEP;
break;
case "allKeep":
untokenizable = UntokenizableOptions.ALL_KEEP;
break;
default:
throw new IllegalArgumentException("SpanishLexer: Invalid option value in constructor: " + key + ": " + value);
}
} else if ("strictTreebank3".equals(key)) {
strictTreebank3 = val;
} else {
throw new IllegalArgumentException(String.format("%s: Invalid options key in constructor: %s%n", this.getClass().getName(), key));
}
}
// this.seenUntokenizableCharacter = false; // unnecessary, it's default initialized
if (invertible) {
if ( ! (tf instanceof CoreLabelTokenFactory)) {
throw new IllegalArgumentException("SpanishLexer: the invertible option requires a CoreLabelTokenFactory");
}
prevWord = (CoreLabel) tf.makeToken("", 0, 0);
prevWordAfter = new StringBuilder();
}
}
View on GitHub (pinned to 1b7edd19c4)