{"record":{"id":"b62e29d72a4deeaf","repo":"stanfordnlp/CoreNLP","slug":"need-at-least-one-component","errorCode":null,"errorMessage":"Need at least one component!","messagePattern":"Need at least one component!","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/stats/DataSeries.java","lineNumber":319,"sourceCode":"        yData.add(x * x);\n      }\n\n      System.out.println(yData.toListPairDouble());\n\n    }\n\n  }\n\n\n  // .......................................................................\n\n  public static class AverageDataSeries implements DataSeries {\n\n    private DataSeries[] components;\n\n    public AverageDataSeries(DataSeries[] components) {\n      if (components == null || components.length < 1)\n        throw new IllegalArgumentException(\"Need at least one component!\");\n      this.components = new DataSeries[components.length];\n      for (int i = 0; i < components.length; i++) {\n        if (components[i] == null)\n          throw new IllegalArgumentException(\"Can't have null components!\");\n        this.components[i] = components[i];\n      }\n      domain();                         // to ensure domains are same\n    }\n\n    public String name() {\n      StringBuilder name = new StringBuilder();\n      name.append(\"avg(\");\n      boolean flag = false;\n      for (DataSeries series : components) {\n        if (flag) name.append(\", \"); else flag = true;\n        name.append(series.name());\n      }\n      name.append(\")\");","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/stats/DataSeries.java#L301-L337","documentation":"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.","triggerScenarios":"Calling `new AverageDataSeries(new DataSeries[0])` or `new AverageDataSeries(null)`.","commonSituations":"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.","solutions":["Check the component array for null/length 0 before constructing AverageDataSeries and handle the empty case (skip averaging, return a placeholder series).","Ensure the code that populates the components array always adds at least one series.","Wrap the constructor call in a guard that throws/logs a clearer domain-specific message."],"exampleFix":"// before\nAverageDataSeries avg = new AverageDataSeries(seriesArray); // throws when empty\n// after\nif (seriesArray == null || seriesArray.length == 0) {\n  throw new IllegalArgumentException(\"No data series loaded; cannot average\");\n}\nAverageDataSeries avg = new AverageDataSeries(seriesArray);","handlingStrategy":"validation","validationCode":"if (components == null || components.length < 1) {\n  throw new IllegalArgumentException(\"Need at least one DataSeries to average\");\n}\nAverageDataSeries avg = new AverageDataSeries(components);","typeGuard":null,"tryCatchPattern":"try {\n  avg = new AverageDataSeries(components);\n} catch (IllegalArgumentException e) {\n  log.warn(\"No series to average: {}\", e.getMessage());\n  avg = null; // or a default/empty series\n}","preventionTips":["Check array length before constructing averaging series.","Make the producer of the component array guarantee at least one element.","Fail early with a domain-specific message when no data was loaded."],"tags":["empty-collection","constructor","validation"],"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"}