stanfordnlp/CoreNLP · error · IllegalArgumentException

Input arrays must have equal length!

Error message

Input arrays must have equal length!

What it means

sigLevelByApproxRand pairs outcomes of two random variables element-wise, so A and B must have the same length. When A.length != B.length the pairing is impossible and an IllegalArgumentException("Input arrays must have equal length!") is thrown before any computation.

Solutions

  1. Ensure both arrays are built over the exact same instances; align/filter them together before the call.
  2. Verify the upstream evaluation loop emits one score per instance per system (check for silently skipped instances).
  3. Add an assertion/log of A.length == B.length in the evaluation harness before running significance tests.
  4. Catch IllegalArgumentException and flag the comparison as invalid rather than proceeding.

Example fix

// before
double p = ArrayMath.sigLevelByApproxRand(scoresA, scoresB, 1000);
// after
if (scoresA.length != scoresB.length) {
  throw new IllegalStateException("misaligned evaluation arrays: " + scoresA.length + " vs " + scoresB.length);
}
double p = ArrayMath.sigLevelByApproxRand(scoresA, scoresB, 1000);
Defensive patterns

Strategy: validation

Validate before calling

if (a.length != b.length) {
  throw new IllegalStateException("misaligned samples: " + a.length + " vs " + b.length);
}

Try / catch

try {
  p = ArrayMath.sigLevelByApproxRand(a, b, iterations);
} catch (IllegalArgumentException e) {
  // report misaligned evaluation arrays
}

Prevention

When it happens

Trigger: Calling sigLevelByApproxRand(double[] A, double[] B, int iterations) where A and B were collected over different instance sets — e.g. one system skipped or dropped instances, or metrics were filtered asymmetrically.

Common situations: Comparing two NLP system outputs where one pipeline produced fewer scores (failed parses, missing files), or mixing per-sentence and per-document metric arrays.

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


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/5c492352a77d0325. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/math/ArrayMath.java:1727

   * significant, that is, the significance level.  This is computed by
   * "approximate randomization".  The test statistic is the absolute
   * difference between the means of the two arrays.  A randomized test
   * statistic is computed the same way after initially randomizing the
   * arrays by swapping each pair of elements with 50% probability.  For
   * the given number of iterations, we generate a randomized test
   * statistic and compare it to the actual test statistic.  The return
   * value is the proportion of iterations in which a randomized test
   * statistic was found to exceed the actual test statistic.
   *
   * @param A Outcome of one r.v.
   * @param B Outcome of another r.v.
   * @return Significance level by randomization
   */
  public static double sigLevelByApproxRand(double[] A, double[] B, int iterations) {
    if (A.length == 0)
      throw new IllegalArgumentException("Input arrays must not be empty!");
    if (A.length != B.length)
      throw new IllegalArgumentException("Input arrays must have equal length!");
    if (iterations <= 0)
      throw new IllegalArgumentException("Number of iterations must be positive!");
    double testStatistic = absDiffOfMeans(A, B, false); // not randomized
    int successes = 0;
    for (int i = 0; i < iterations; i++) {
      double t =  absDiffOfMeans(A, B, true); // randomized
      if (t >= testStatistic) successes++;
    }
    return (double) (successes + 1) / (double) (iterations + 1);
  }

  public static double sigLevelByApproxRand(int[] A, int[] B) {
    return sigLevelByApproxRand(A, B, 1000);
  }

  public static double sigLevelByApproxRand(int[] A, int[] B, int iterations) {
    if (A.length == 0)
      throw new IllegalArgumentException("Input arrays must not be empty!");

View on GitHub (pinned to 1b7edd19c4)