{"record":{"id":"b8caf8d2d08203a9","repo":"redis/jedis","slug":"aggregators-must-not-contain-null-elements","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/TSMRangeParams.java","lineNumber":162,"sourceCode":"\n  /**\n   * Specifies multiple aggregators to be applied in a single {@code TS.MRANGE} / {@code TS.MREVRANGE} 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 TSMRangeParams aggregation(AggregationType[] aggregators, long bucketDuration) {\n    if (aggregators != null) {\n      if (aggregators.length == 0) {\n        throw new IllegalArgumentException(\"Aggregators must be non-null and non-empty\");\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    return this;\n  }\n\n  /**\n   * This requires AGGREGATION.\n   */\n  public TSMRangeParams bucketTimestamp(String bucketTimestamp) {\n    this.bucketTimestamp = encode(bucketTimestamp);\n    return this;\n  }","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/timeseries/TSMRangeParams.java#L144-L180","documentation":"TSMRangeParams.aggregation(AggregationType[], long) also rejects arrays containing null elements with IllegalArgumentException(\"Aggregators must not contain null elements\"). A null entry would produce an invalid AGGREGATION clause on the wire, so it is refused at parameter-construction time.","triggerScenarios":"Passing an array such as {AggregationType.AVG, null}, typically produced by pre-sized arrays (new AggregationType[n]) that were only partially filled, or lists converted with nulls coming from config/parsers.","commonSituations":"Allocating new AggregationType[size] and populating fewer than size entries; deserializing aggregator lists from JSON/YAML where unknown values map to null; optional aggregation slots left unset in the array.","solutions":["Build the array with exact size, e.g. via list.toArray(new AggregationType[0]), rather than a pre-sized array with unfilled slots.","Filter nulls before calling: Arrays.stream(arr).filter(Objects::nonNull).toArray(AggregationType[]::new).","Fix the config/parser so unknown aggregator names are rejected or mapped to valid AggregationType values, not null."],"exampleFix":"// before\nAggregationType[] aggs = new AggregationType[3];\naggs[0] = AggregationType.AVG;\nparams.aggregation(aggs, 60000); // nulls -> throws\n// after\nList<AggregationType> aggs = new ArrayList<>();\naggs.add(AggregationType.AVG);\nparams.aggregation(aggs.toArray(new AggregationType[0]), 60000);","handlingStrategy":"validation","validationCode":"AggregationType[] cleaned = Arrays.stream(aggs).filter(Objects::nonNull).toArray(AggregationType[]::new);\nif (cleaned.length == 0) throw new IllegalArgumentException(\"No valid aggregators\");\nparams.aggregation(cleaned, bucketDuration);","typeGuard":"boolean allNonNull(AggregationType[] a) {\n  return Arrays.stream(a).allMatch(Objects::nonNull);\n}","tryCatchPattern":"try {\n  params.aggregation(aggs, bucketMs);\n} catch (IllegalArgumentException e) {\n  log.error(\"Null aggregator in array, check config mapping: {}\", e.getMessage());\n  throw e;\n}","preventionTips":["Avoid pre-sized arrays; build lists and convert with toArray(new AggregationType[0]).","Parse aggregator names with a strict enum lookup that rejects unknown values instead of yielding null.","Add Objects::nonNull filtering as a standard pre-processing step for externally supplied arrays."],"tags":["java","timeseries","validation","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"}