stanfordnlp/CoreNLP · error · IllegalArgumentException
to length:" + to.length + " from length:" + from.length
Error message
to length:" + to.length + " from length:" + from.length
What it means
The float[] overload of ArrayMath.pairwiseAddInPlace requires both arrays to have identical length, since it adds from[i] into to[i] element-wise. A length mismatch means the operation is undefined, so it throws IllegalArgumentException immediately with both lengths in the message.
Solutions
- Check to.length == from.length before calling, or pad/trim the shorter array.
- Rebuild one of the arrays from the same feature space/model version as the other.
- Catch IllegalArgumentException and log both lengths to identify which pipeline stage produced the mismatched vector.
Example fix
// before ArrayMath.pairwiseAddInPlace(a, b); // a.length=10, b.length=9 // after if (a.length == b.length) ArrayMath.pairwiseAddInPlace(a, b);
Defensive patterns
Strategy: validation
Validate before calling
if (to.length != from.length) throw new IllegalArgumentException("cannot pairwise-add float arrays: " + to.length + " vs " + from.length); Type guard
boolean sameLength(float[] a, float[] b) { return a.length == b.length; } Try / catch
try { ArrayMath.pairwiseAddInPlace(to, from); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("to length:")) { /* resize or abort */ } else throw e; } Prevention
- Centralize vector creation so dimensions come from one source of truth
- Version-check model artifacts against feature extractors
- Assert array lengths in unit tests around vector math
When it happens
Trigger: Calling ArrayMath.addInPlace or pairwiseAddInPlace(float[], float[]) with arrays produced from different models, different feature counts, or truncated/sliced arrays of unequal size.
Common situations: Mixing feature vectors from different feature alphabets; loading weights checkpointed with an older model version whose dimensionality changed.
Related errors
- Arrays do not have the same length.
- Array must be sorted!
- dim should be an array of size 2.
- Vector of incorrect size passed to applyInitialHessian in…
- Word vectors file has dimension too small for requested…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/04e5b2c977a6c852.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/math/ArrayMath.java:302
return result;
}
/**
* raises each entry in array a by power c
*/
public static float[] pow(float[] a, float c) {
float[] result = new float[a.length];
for (int i = 0; i < a.length; i++) {
result[i] = (float) Math.pow(a[i], c);
}
return result;
}
// OPERATIONS WITH TWO ARRAYS - DESTRUCTIVE
public static void pairwiseAddInPlace(float[] to, float[] from) {
if (to.length != from.length) {
throw new IllegalArgumentException("to length:" + to.length + " from length:" + from.length);
}
for (int i = 0; i < to.length; i++) {
to[i] += from[i];
}
}
/**
* Add the two 1d arrays in place of {@code to}.
*
* @throws java.lang.IllegalArgumentException If {@code to} and {@code from} are not of the same dimensions
*/
public static void pairwiseAddInPlace(double[] to, double[] from) {
if (to.length != from.length) {
throw new IllegalArgumentException("to length:" + to.length + " from length:" + from.length);
}
for (int i = 0; i < to.length; i++) {
to[i] += from[i];
}View on GitHub (pinned to 1b7edd19c4)