stanfordnlp/CoreNLP · error · IllegalArgumentException

Need at least one component!

Error message

Need at least one component!

What it means

AverageDataSeries computes the average of several DataSeries components, which requires at least one component. The constructor validates the input array and throws IllegalArgumentException when the array is null or empty, since averaging zero series is meaningless.

Solutions

  1. Check the component array for null/length 0 before constructing AverageDataSeries and handle the empty case (skip averaging, return a placeholder series).
  2. Ensure the code that populates the components array always adds at least one series.
  3. Wrap the constructor call in a guard that throws/logs a clearer domain-specific message.

Example fix

// before
AverageDataSeries avg = new AverageDataSeries(seriesArray); // throws when empty
// after
if (seriesArray == null || seriesArray.length == 0) {
  throw new IllegalArgumentException("No data series loaded; cannot average");
}
AverageDataSeries avg = new AverageDataSeries(seriesArray);
Defensive patterns

Strategy: validation

Validate before calling

if (components == null || components.length < 1) {
  throw new IllegalArgumentException("Need at least one DataSeries to average");
}
AverageDataSeries avg = new AverageDataSeries(components);

Try / catch

try {
  avg = new AverageDataSeries(components);
} catch (IllegalArgumentException e) {
  log.warn("No series to average: {}", e.getMessage());
  avg = null; // or a default/empty series
}

Prevention

When it happens

Trigger: Calling `new AverageDataSeries(new DataSeries[0])` or `new AverageDataSeries(null)`.

Common situations: Building the component array programmatically from a filter or stream that matched nothing (empty config, no data files loaded), then passing it straight to the constructor.

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/b62e29d72a4deeaf. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/stats/DataSeries.java:319

        yData.add(x * x);
      }

      System.out.println(yData.toListPairDouble());

    }

  }


  // .......................................................................

  public static class AverageDataSeries implements DataSeries {

    private DataSeries[] components;

    public AverageDataSeries(DataSeries[] components) {
      if (components == null || components.length < 1)
        throw new IllegalArgumentException("Need at least one component!");
      this.components = new DataSeries[components.length];
      for (int i = 0; i < components.length; i++) {
        if (components[i] == null)
          throw new IllegalArgumentException("Can't have null components!");
        this.components[i] = components[i];
      }
      domain();                         // to ensure domains are same
    }

    public String name() {
      StringBuilder name = new StringBuilder();
      name.append("avg(");
      boolean flag = false;
      for (DataSeries series : components) {
        if (flag) name.append(", "); else flag = true;
        name.append(series.name());
      }
      name.append(")");

View on GitHub (pinned to 1b7edd19c4)