stanfordnlp/CoreNLP · error · IllegalArgumentException

Input arrays must not be empty!

Error message

Input arrays must not be empty!

What it means

ArrayMath.sigLevelByApproxRand(double[] A, double[] B, int iterations) computes a randomization-test significance level for the difference of means. It requires non-empty, equal-length inputs and a positive iteration count; an empty A (or B) makes the test statistic undefined, so an IllegalArgumentException is thrown immediately.

Solutions

  1. Check A.length > 0 && B.length > 0 (and equal lengths) before calling; skip the significance test when either sample is empty.
  2. Fix the upstream data loading/evaluation step that yielded an empty result set.
  3. Catch IllegalArgumentException and report the comparison as not-computable rather than crashing the evaluation job.
  4. Ensure both systems under comparison scored the same non-empty set of instances.

Example fix

// before
double p = ArrayMath.sigLevelByApproxRand(sysA, sysB, 1000);
// after
double p = (sysA.length > 0 && sysB.length > 0 && sysA.length == sysB.length)
    ? ArrayMath.sigLevelByApproxRand(sysA, sysB, 1000)
    : Double.NaN; // test not computable
Defensive patterns

Strategy: validation

Validate before calling

boolean ok = a != null && b != null && a.length > 0 && b.length > 0 && a.length == b.length && iterations > 0;
if (!ok) { /* skip test or report not-computable */ }

Try / catch

try {
  p = ArrayMath.sigLevelByApproxRand(a, b, iterations);
} catch (IllegalArgumentException e) {
  p = Double.NaN; // mark comparison as not computable
}

Prevention

When it happens

Trigger: Calling sigLevelByApproxRand(new double[0], B, n) — or with an empty B, since only A's length is checked for emptiness but A.length != B.length is also enforced — with zero-length arrays.

Common situations: Running significance tests in evaluation pipelines where one system produced no results (empty metric list, empty test split), often from a config or data-loading mistake.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

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

   * classifiers on a sequence of inputs.  Returns the estimated
   * probability that the difference between the means of A and B is not
   * 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) {

View on GitHub (pinned to 1b7edd19c4)