stanfordnlp/CoreNLP · error · IllegalArgumentException
Can't have null components!
Error message
Can't have null components!
What it means
AverageDataSeries stores every component to later average and compare domains; null components cannot be averaged. The constructor loops over the array and throws IllegalArgumentException as soon as it encounters a null element.
Solutions
- Filter out null entries before constructing: use a List, add non-null series, then toArray.
- Fix the producer code to omit null series instead of inserting null placeholders.
- Validate the array with a null check loop before calling the constructor to give a clearer message.
Example fix
// before DataSeries[] comps = new DataSeries[files.length]; // slots may stay null AverageDataSeries avg = new AverageDataSeries(comps); // after List<DataSeries> comps = new ArrayList<>(); for (DataSeries s : maybeNull) if (s != null) comps.add(s); AverageDataSeries avg = new AverageDataSeries(comps.toArray(new DataSeries[0]));
Defensive patterns
Strategy: validation
Validate before calling
for (DataSeries s : components) {
if (s == null) throw new IllegalArgumentException("Null component in series array");
}
AverageDataSeries avg = new AverageDataSeries(components); Type guard
boolean allNonNull(DataSeries[] arr) { return arr != null && java.util.Arrays.stream(arr).allMatch(java.util.Objects::nonNull); } Try / catch
try {
avg = new AverageDataSeries(components);
} catch (IllegalArgumentException e) {
components = java.util.Arrays.stream(components).filter(java.util.Objects::nonNull).toArray(DataSeries[]::new);
avg = components.length > 0 ? new AverageDataSeries(components) : null;
} Prevention
- Use List<DataSeries> and add only non-null series instead of pre-sized arrays.
- Never insert null placeholders into series arrays.
- Filter with Objects::nonNull before construction.
When it happens
Trigger: Calling `new AverageDataSeries(new DataSeries[]{seriesA, null, seriesC})` or passing an array produced by code that leaves null slots (e.g. pre-sized arrays partially filled).
Common situations: Arrays built with `new DataSeries[n]` and only some slots assigned, or optional data sources that returned null instead of skipping.
Related errors
- Need at least one component!
- Unknown position in AddDep operation
- Value cannot be both true and false.
- We need at least 2 extractors for ExtractorMerger to make…
- Argument " + i + " to class constructor is null
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/229d30db0484739e.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/stats/DataSeries.java:323
}
}
// .......................................................................
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(")");
return name.toString();
}
public double get(int i) {View on GitHub (pinned to 1b7edd19c4)