{"record":{"id":"482845f1024cba59","repo":"redis/jedis","slug":"aggregators-must-not-contain-null-elements-482845","errorCode":null,"errorMessage":"Aggregators must not contain null elements","messagePattern":"Aggregators must not contain null elements","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/timeseries/TSRangeParams.java","lineNumber":139,"sourceCode":"\n  /**\n   * Specifies multiple aggregators to be applied in a single {@code TS.RANGE} / {@code TS.REVRANGE} call. Aggregators are\n   * sent on the wire in the given order and the response values appear in the same order in {@link TSElement#getValues()}.\n   * Single-element arrays are accepted and behave like {@link #aggregation(AggregationType, long)}.\n   *\n   * @param aggregators ordered, non-empty list of aggregators\n   * @param bucketDuration aggregation bucket duration in milliseconds\n   * @return this\n   * @throws IllegalArgumentException if {@code aggregators} is empty\n   */\n  public TSRangeParams aggregation(AggregationType[] aggregators, long bucketDuration) {\n    if (aggregators != null) {\n      if (aggregators.length == 0) {\n        throw new IllegalArgumentException(\"At least one aggregator is required\");\n      }\n      for (AggregationType a : aggregators) {\n        if (a == null) {\n          throw new IllegalArgumentException(\"Aggregators must not contain null elements\");\n        }\n      }\n      this.aggregators = aggregators;\n      this.bucketDuration = bucketDuration;\n    } else {\n      this.aggregators = null;\n      this.bucketDuration = 0;\n    }\n\n    return this;\n  }\n\n  /**\n   * This requires AGGREGATION.\n   */\n  public TSRangeParams bucketTimestamp(String bucketTimestamp) {\n    this.bucketTimestamp = encode(bucketTimestamp);\n    return this;","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/timeseries/TSRangeParams.java#L121-L157","documentation":"TSRangeParams.aggregation(AggregationType[] aggregators, long bucketDuration) rejects null elements inside the aggregator array. A null AggregationType cannot be encoded into the AGGREGATION argument of TS.RANGE, so the library throws IllegalArgumentException during parameter building.","triggerScenarios":"Calling TSRangeParams.aggregation(new AggregationType[]{AggregationType.MIN, null}, bucketDuration), or arrays produced by AggregationType[n] pre-sizing with unfilled slots.","commonSituations":"Mapping user-supplied aggregation names via a lookup that returns null for unknown values; deserialized configuration containing incomplete aggregator lists.","solutions":["Replace null entries with valid AggregationType constants (MIN, MAX, AVG, SUM, COUNT, etc.).","Fail at parse time when a configured aggregation name cannot be resolved to an AggregationType, instead of storing null.","Filter with Objects::nonNull only if trailing nulls are semantically unwanted — but prefer fixing the producer so no nulls are created."],"exampleFix":"// before\nAggregationType[] aggs = new AggregationType[2];\naggs[0] = AggregationType.SUM;\nparams.aggregation(aggs, 10000); // aggs[1] == null -> throws\n// after\nAggregationType[] aggs = new AggregationType[]{AggregationType.SUM, AggregationType.AVG};\nparams.aggregation(aggs, 10000);","handlingStrategy":"validation","validationCode":"if (Arrays.stream(aggs).anyMatch(Objects::isNull)) {\n  throw new IllegalStateException(\"null aggregator in config\");\n}\nparams.aggregation(aggs, bucketMs);","typeGuard":"static AggregationType[] nonNullAggs(AggregationType[] in) { return Arrays.stream(in).filter(Objects::nonNull).toArray(AggregationType[]::new); }","tryCatchPattern":"try { params.aggregation(aggs, bucketMs); } catch (IllegalArgumentException e) { throw new ConfigurationException(\"null aggregator\", e); }","preventionTips":["Fail at config parse time on unknown aggregation names","Initialize arrays with all values, or use List.of(...)","Run a null-scan on builder inputs in tests"],"tags":["java","validation","timeseries","null-check"],"backgroundTag":"null-argument","analyzedSha":"6dac31d4c224fb3257c216f3985340c6f500cdcb","analyzedAt":"2026-09-08T04:55:01.204Z","contentChangedAt":"2026-09-08T04:55:01.204Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}