stanfordnlp/CoreNLP · error · IllegalArgumentException
Invalid projection function: " +…
Error message
Invalid projection function: " + Arrays.toString(projectionFunction)
What it means
The Polarity(byte[]) constructor validates that the projection function array is exactly length 7 (one slot per NaturalLogicRelation) before using it. If the caller supplies an array of any other length, it throws IllegalArgumentException reporting the offending array. The length 7 corresponds to the seven natural-logic relations the projection table must cover.
Solutions
- Ensure the array passed to the constructor has exactly 7 entries, indexed by NaturalLogicRelation ordinal
- Pad or truncate a shorter/longer source array to 7 before constructing, mapping old ordinals correctly
- Check version compatibility of any serialized projection data
Example fix
// before Polarity p = new Polarity(myTable); // myTable.length == 5 // after byte[] table = new byte[7]; System.arraycopy(myTable, 0, table, 0, Math.min(myTable.length, 7)); Polarity p = new Polarity(table);
Defensive patterns
Strategy: validation
Validate before calling
if (fn == null || fn.length != 7) throw new IllegalArgumentException("projection table must have 7 entries, got " + (fn == null ? "null" : fn.length)); Try / catch
try { new Polarity(fn); } catch (IllegalArgumentException e) { /* rebuild table from NaturalLogicRelation ordinals */ } Prevention
- Always build projection tables indexed by NaturalLogicRelation ordinal
- Validate serialized data lengths before constructing Polarity
When it happens
Trigger: new Polarity(byte[]) with an array whose length != 7 — e.g. a hand-written projection table, a truncated byte[] read from a model file, or an array built from an older relation enum with a different cardinality.
Common situations: Hand-crafting custom polarity/projection tables; deserializing serialized Polarity data produced by a different CoreNLP version where the relation count changed.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Cannot put a child trie with no keys
- CoreMap must have either a Calendar or DocDate annotation
- Could not compute span from tokens!
- ERROR: numberOfKeys must be > size of counter !
- Invalid arguments to
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/82ccbdf5b245f715.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/naturalli/Polarity.java:51
}
} else {
for (int rel = 0; rel < 7; ++rel) {
NaturalLogicRelation relation = NaturalLogicRelation.byFixedIndex(rel);
for (int op = operatorsInNarrowingScopeOrder.size() - 1; op >= 0; --op) {
relation = project(relation, operatorsInNarrowingScopeOrder.get(op).first, operatorsInNarrowingScopeOrder.get(op).second);
}
projectionFunction[rel] = (byte) relation.fixedIndex;
}
}
}
/**
* Create a polarity item by directly copying the projection function from {@link edu.stanford.nlp.naturalli.NaturalLogicRelation}s to
* their projected relation.
*/
public Polarity(byte[] projectionFunction) {
if (projectionFunction.length != 7) {
throw new IllegalArgumentException("Invalid projection function: " + Arrays.toString(projectionFunction));
}
for (int i = 0; i < 7; ++i) {
if (projectionFunction[i] < 0 || projectionFunction[i] > 6) {
throw new IllegalArgumentException("Invalid projection function: " + Arrays.toString(projectionFunction));
}
}
System.arraycopy(projectionFunction, 0, this.projectionFunction, 0, 7);
}
/**
* Encode the projection table in painful detail.
*
* @param input The input natural logic relation to project up through the operator.
* @param mono The monotonicity of the operator we are projecting through.
* @param type The monotonicity type of the operator we are projecting through.
*
* @return The projected relation, once passed through an operator with the given specifications.
*/View on GitHub (pinned to 1b7edd19c4)