{"record":{"id":"4dda2a8b22a17fcf","repo":"stanfordnlp/CoreNLP","slug":"input-arrays-must-not-be-empty","errorCode":null,"errorMessage":"Input arrays must not be empty!","messagePattern":"Input arrays must not be empty!","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/math/ArrayMath.java","lineNumber":1725,"sourceCode":"   * classifiers on a sequence of inputs.  Returns the estimated\n   * probability that the difference between the means of A and B is not\n   * significant, that is, the significance level.  This is computed by\n   * \"approximate randomization\".  The test statistic is the absolute\n   * difference between the means of the two arrays.  A randomized test\n   * statistic is computed the same way after initially randomizing the\n   * arrays by swapping each pair of elements with 50% probability.  For\n   * the given number of iterations, we generate a randomized test\n   * statistic and compare it to the actual test statistic.  The return\n   * value is the proportion of iterations in which a randomized test\n   * statistic was found to exceed the actual test statistic.\n   *\n   * @param A Outcome of one r.v.\n   * @param B Outcome of another r.v.\n   * @return Significance level by randomization\n   */\n  public static double sigLevelByApproxRand(double[] A, double[] B, int iterations) {\n    if (A.length == 0)\n      throw new IllegalArgumentException(\"Input arrays must not be empty!\");\n    if (A.length != B.length)\n      throw new IllegalArgumentException(\"Input arrays must have equal length!\");\n    if (iterations <= 0)\n      throw new IllegalArgumentException(\"Number of iterations must be positive!\");\n    double testStatistic = absDiffOfMeans(A, B, false); // not randomized\n    int successes = 0;\n    for (int i = 0; i < iterations; i++) {\n      double t =  absDiffOfMeans(A, B, true); // randomized\n      if (t >= testStatistic) successes++;\n    }\n    return (double) (successes + 1) / (double) (iterations + 1);\n  }\n\n  public static double sigLevelByApproxRand(int[] A, int[] B) {\n    return sigLevelByApproxRand(A, B, 1000);\n  }\n\n  public static double sigLevelByApproxRand(int[] A, int[] B, int iterations) {","sourceCodeStart":1707,"sourceCodeEnd":1743,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/math/ArrayMath.java#L1707-L1743","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check A.length > 0 && B.length > 0 (and equal lengths) before calling; skip the significance test when either sample is empty.","Fix the upstream data loading/evaluation step that yielded an empty result set.","Catch IllegalArgumentException and report the comparison as not-computable rather than crashing the evaluation job.","Ensure both systems under comparison scored the same non-empty set of instances."],"exampleFix":"// before\ndouble p = ArrayMath.sigLevelByApproxRand(sysA, sysB, 1000);\n// after\ndouble p = (sysA.length > 0 && sysB.length > 0 && sysA.length == sysB.length)\n    ? ArrayMath.sigLevelByApproxRand(sysA, sysB, 1000)\n    : Double.NaN; // test not computable","handlingStrategy":"validation","validationCode":"boolean ok = a != null && b != null && a.length > 0 && b.length > 0 && a.length == b.length && iterations > 0;\nif (!ok) { /* skip test or report not-computable */ }","typeGuard":null,"tryCatchPattern":"try {\n  p = ArrayMath.sigLevelByApproxRand(a, b, iterations);\n} catch (IllegalArgumentException e) {\n  p = Double.NaN; // mark comparison as not computable\n}","preventionTips":["Guard all length/iteration preconditions in evaluation harness code","Verify data loading produced non-empty result sets before statistics","Treat empty system output as a upstream failure worth reporting","Centralize significance testing behind one validated helper"],"tags":["statistics","empty-array","argument-validation","hypothesis-testing"],"backgroundTag":"empty-required-field","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}