{"record":{"id":"4a10c404f2e9f7a6","repo":"apache/druid","slug":"element-of-intervals-is-null","errorCode":null,"errorMessage":"Element of intervals is null","messagePattern":"Element of intervals is null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/java/util/common/JodaUtils.java","lineNumber":126,"sourceCode":"    {\n      private Interval previous;\n\n      @Override\n      public boolean hasNext()\n      {\n        return peekingIterator.hasNext();\n      }\n\n      @Override\n      public Interval next()\n      {\n        if (!hasNext()) {\n          throw new NoSuchElementException();\n        }\n\n        Interval currInterval = peekingIterator.next();\n        if (currInterval == null) {\n          throw new IAE(\"Element of intervals is null\");\n        }\n\n        // check sorted ascending:\n        verifyAscendingSortOrder(previous, currInterval);\n\n        previous = currInterval;\n\n        while (hasNext()) {\n          Interval next = peekingIterator.peek();\n          if (next == null) {\n            throw new IAE(\"Element of intervals is null\");\n          }\n\n          if (currInterval.abuts(next)) {\n            currInterval = new Interval(currInterval.getStart(), next.getEnd());\n            peekingIterator.next();\n          } else if (currInterval.overlaps(next)) {\n            DateTime nextEnd = next.getEnd();","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/common/JodaUtils.java#L108-L144","documentation":"JodaUtils.mergeIntervals' iterator (next method) throws this IAE when the input iterable of org.joda.time.Interval contains a null element. The utility requires a finite, non-null, sorted list of intervals to merge adjacent/overlapping ones. A null element cannot be ordered or merged, so it is rejected immediately.","triggerScenarios":"Calling JodaUtils.mergeIntervals(List.of(interval1, null)) or passing a collection built from nullable sources (e.g. deserialized specs) where some entries failed to populate.","commonSituations":"Intervals read from JSON configs where a segment/interval entry is null; building interval lists from external systems with missing rows; concatenating lists where nulls act as placeholders.","solutions":["Filter nulls before merging: intervals.removeIf(Objects::isNull) or streams filter(Objects::nonNull)","Fix the producer that inserts null intervals into the list","Validate list contents at the config-loading boundary and fail with a clearer context-specific message"],"exampleFix":"// before\nJodaUtils.mergeIntervals(Arrays.asList(iv1, null)); // IAE\n// after\nList<Interval> clean = intervals.stream().filter(Objects::nonNull).collect(Collectors.toList());\nJodaUtils.mergeIntervals(clean);","handlingStrategy":"validation","validationCode":"List<Interval> nonNull = intervals.stream().filter(Objects::nonNull).collect(Collectors.toList());\nif (nonNull.size() != intervals.size()) {\n  log.warn(\"Dropped %d null intervals\", intervals.size() - nonNull.size());\n}","typeGuard":"static boolean hasNoNullIntervals(List<Interval> list) {\n  return list.stream().allMatch(Objects::nonNull);\n}","tryCatchPattern":"try {\n  return JodaUtils.mergeIntervals(intervals);\n} catch (IllegalArgumentException e) {\n  throw new IllegalStateException(\"interval list contains null elements\", e);\n}","preventionTips":["Filter nulls right where the interval list is assembled","Avoid using null as a placeholder in interval collections","Validate deserialized specs before converting to Interval lists"],"tags":["intervals","null","joda-time"],"backgroundTag":"null-argument","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}