stanfordnlp/CoreNLP · error · IllegalArgumentException
Cannot parse Trilean from string: " + value
Error message
Cannot parse Trilean from string: " + value
What it means
Trilean.fromString(value) throws IllegalArgumentException when the input string matches none of the accepted spellings (true/t/yes/y/1, false/f/no/n/0, unknown/unk/u, case-insensitively). It is a strict parser for user-provided Trilean literals.
Solutions
- Pass only the documented spellings: true/t/yes/y/1, false/f/no/n/0, unknown/unk/u (case-insensitive).
- Trim and normalize the input before calling fromString.
- Pre-validate with a regex/canonicalization step and give the user a clear message on mismatch.
- Catch IllegalArgumentException and fall back to UNKNOWN with a warning.
Example fix
// before
Trilean t = Trilean.fromString(props.getProperty("flag")); // "enabled"
// after
String v = props.getProperty("flag", "unknown").trim().toLowerCase();
if (!v.matches("true|t|yes|y|1|false|f|no|n|0|unknown|unk|u"))
throw new IllegalArgumentException("Unsupported flag value: " + v);
Trilean t = Trilean.fromString(v); Defensive patterns
Strategy: validation
Validate before calling
String v = value == null ? "" : value.trim().toLowerCase();
if (!v.matches("true|t|yes|y|1|false|f|no|n|0|unknown|unk|u"))
throw new IllegalArgumentException("Not a Trilean literal: " + value); Try / catch
try {
Trilean t = Trilean.fromString(value);
} catch (IllegalArgumentException e) {
Trilean t = Trilean.UNKNOWN; // or rethrow with friendlier message
} Prevention
- Trim and lowercase user input before parsing.
- Publish the accepted literals (true/false/unknown and short forms) in config docs.
- Canonicalize config values in one shared helper.
When it happens
Trigger: fromString("True ") with trailing whitespace variants not trimmed? (matching is exact after lowercase), or any unrecognized token such as "TRUE!" or "maybe" passed to fromString.
Common situations: Parsing config files or command-line flags where users typed values outside the accepted set (e.g. "on", "enabled", "YESS"); untrimmed input from properties files.
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
- Too many columns: / (offset: )
- Too few columns: / (offset: )
- Bad data format:
- Bad number put into wordToNumber. Word is: \"" + input +…
- Error in wordToNumber function.
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/c4b6ecc5e346c7d1.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/util/Trilean.java:225
} else {
return FALSE;
}
}
public static Trilean fromString(String value) {
switch(value.toLowerCase()) {
case "true":
case "t":
return TRUE;
case "false":
case "f":
return FALSE;
case "unknown":
case "unk":
case "u":
return UNKNOWN;
default:
throw new IllegalArgumentException("Cannot parse Trilean from string: " + value);
}
}
/** The static value for True */
public static Trilean TRUE = new Trilean(true, false);
/** The static value for False */
public static Trilean FALSE = new Trilean(false, true);
/** The static value for Unknown (neither true or false) */
public static Trilean UNKNOWN = new Trilean(false, false);
}
View on GitHub (pinned to 1b7edd19c4)