stanfordnlp/CoreNLP · error · IllegalArgumentException
is not a legal LogPrior.
Error message
is not a legal LogPrior.
What it means
LogPrior.intToType converts a legacy integer code to a LogPriorType by matching against enum ordinals. If the integer does not match any enum ordinal, an IllegalArgumentException naming the offending int is thrown. This protects the int-based constructor LogPrior(int, double, double) against stale or out-of-range codes.
Solutions
- Use a valid integer ordinal from LogPriorType.values(), or better, construct with the enum: new LogPrior(LogPriorType.QUADRATIC, sigma, epsilon)
- Check whether the int came from a saved config produced with a different library version and re-map it
- Iterate LogPriorType.values() to print valid ordinals and pick the right one
Example fix
// before LogPrior prior = new LogPrior(7, 1.0, 0.1); // after LogPrior prior = new LogPrior(LogPrior.LogPriorType.QUADRATIC, 1.0, 0.1);
Defensive patterns
Strategy: type-guard
Validate before calling
int n = LogPriorType.values().length;
if (intPrior < 0 || intPrior >= n)
throw new IllegalArgumentException("intPrior must be in [0," + (n-1) + "]: " + intPrior); Type guard
boolean isValidLogPriorInt(int code) {
return code >= 0 && code < LogPrior.LogPriorType.values().length;
} Try / catch
try {
LogPrior p = new LogPrior(intPrior, sigma, epsilon);
} catch (IllegalArgumentException e) {
LogPrior p = new LogPrior(LogPrior.LogPriorType.QUADRATIC, sigma, epsilon);
} Prevention
- Prefer enum-based constructors over int codes to avoid ordinal drift across versions
- When migrating saved configs, re-map integer codes against the current LogPriorType.values()
- Never persist raw ordinals; persist the enum name instead
When it happens
Trigger: Calling new LogPrior(intPrior, sigma, epsilon) with an integer outside 0..LogPriorType.values().length-1, or an integer serialized under an older version of the enum whose ordinal no longer exists.
Common situations: Persisted model/config files storing numeric prior codes that no longer match the current enum order after the library was upgraded; hand-written integer constants that don't correspond to any ordinal.
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 LogPriorType:
- RuntimeIOException wrapping IOException
- Unsupported subScoreType
- Invalid metricType
- Invalid sub score type
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/d8b952fdaf3481dd.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/classify/LogPrior.java:69
}
public LogPrior(int intPrior) {
this(intPrior, 1.0, 0.1);
}
public LogPrior(LogPriorType type) {
this(type, 1.0, 0.1);
}
// why isn't this functionality in enum?
private static LogPriorType intToType(int intPrior) {
LogPriorType[] values = LogPriorType.values();
for (LogPriorType val : values) {
if (val.ordinal() == intPrior) {
return val;
}
}
throw new IllegalArgumentException(intPrior + " is not a legal LogPrior.");
}
public LogPrior(int intPrior, double sigma, double epsilon) {
this(intToType(intPrior), sigma, epsilon);
}
public LogPrior(LogPriorType type, double sigma, double epsilon) {
this.type = type;
if (type != LogPriorType.ADAPT) {
setSigma(sigma);
setEpsilon(epsilon);
}
}
// this is the C variable in CSFoo's MM paper C = 1/\sigma^2
// private double[] regularizationHyperparameters = null;
View on GitHub (pinned to 1b7edd19c4)