stanfordnlp/CoreNLP · error · java.lang.IllegalArgumentException
Invalid line search option for QNMinimizer.
Error message
Invalid line search option for QNMinimizer.
What it means
The switch over the configured line search type (QNMinimizer.eLineSearchType) hit its default branch because the enum value is not one of the supported options (e.g. BACKTRACKING, MINPACK). This indicates a corrupted or unrecognized line search setting.
Solutions
- Set line search to a supported value: minimizer.setMinimizeType(QNMinimizer.eLineSearchType.BACKTRACKING) or .MINPACK.
- Upgrade/downgrade so all modules use the same CoreNLP version and enum.
- Inspect the current value with reflection/logging before calling minimize().
Example fix
// before minimizer.setMinimizeType(unrecognizedType); // default branch throws // after minimizer.setMinimizeType(QNMinimizer.eLineSearchType.MINPACK);
Defensive patterns
Strategy: validation
Validate before calling
QNMinimizer.eLineSearchType t = minimizer.lineSearchType; // via getter if available
if (t != QNMinimizer.eLineSearchType.BACKTRACKING && t != QNMinimizer.eLineSearchType.MINPACK)
throw new IllegalStateException("Unsupported line search: " + t); Type guard
boolean supported = EnumSet.of(QNMinimizer.eLineSearchType.BACKTRACKING, QNMinimizer.eLineSearchType.MINPACK).contains(type);
Try / catch
try {
minimizer.minimize(f, tol, init);
} catch (IllegalArgumentException e) {
minimizer.setMinimizeType(QNMinimizer.eLineSearchType.MINPACK);
minimizer.minimize(f, tol, init);
} Prevention
- Only assign enum values from the same CoreNLP version that runs the training.
- Pin all modules to one stanford-corenlp version.
- Log the line search type at startup.
When it happens
Trigger: Setting the line search option via setMinimizeType()/reflection/config deserialization to an eLineSearchType value not handled by the switch (only BACKTRACKING and MINPACK cases are covered) and then calling minimize().
Common situations: Deserializing a serialized QNMinimizer whose enum constant comes from a different compiled version of the library; programmatic enum construction; version skew between code that sets the type and the minimizer code.
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
- Not a valid NewlineIsSentenceBreak name
- Unknown format
- Unknown timeAnnotator
- Unknown LogPriorType:
- is not a legal LogPrior.
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/c6a62e74ddd17a02.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/optimization/QNMinimizer.java:1025
double[] newPoint; // initialized in if/else/switch below
if (useOWLQN) {
// only linear search is allowed for OWL-QN
newPoint = lineSearchBacktrackOWL(dFunction, dir, x, newX, grad, value, sb);
sb.append('B');
} else {
// switch between line search options.
switch (lsOpt) {
case BACKTRACK:
newPoint = lineSearchBacktrack(dFunction, dir, x, newX, grad, value, sb);
sb.append('B');
break;
case MINPACK:
newPoint = lineSearchMinPack(dFunction, dir, x, newX, grad, value,
functionTolerance, sb);
sb.append('M');
break;
default:
throw new IllegalArgumentException("Invalid line search option for QNMinimizer.");
}
}
newValue = newPoint[f];
sb.append(' ').append(nf.format(newPoint[a])).append("] ");
// This shouldn't actually evaluate anything since that should have been
// done in the lineSearch.
System.arraycopy(dFunction.derivativeAt(newX), 0, newGrad, 0, newGrad.length);
// This is where all the s, y updates are applied.
qn.update(newX, x, newGrad, rawGrad, newPoint[a]); // step (4) in Galen & Gao 2007
if (useOWLQN) {
System.arraycopy(newGrad, 0, rawGrad, 0, newGrad.length);
// pseudo gradient
newGrad = pseudoGradientOWL(newX, newGrad, dFunction);
}View on GitHub (pinned to 1b7edd19c4)