apache/druid · error · IllegalArgumentException

Element of intervals is null

Error message

Element of intervals is null

What it means

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.

Solutions

  1. Filter nulls before merging: intervals.removeIf(Objects::isNull) or streams filter(Objects::nonNull)
  2. Fix the producer that inserts null intervals into the list
  3. Validate list contents at the config-loading boundary and fail with a clearer context-specific message

Example fix

// before
JodaUtils.mergeIntervals(Arrays.asList(iv1, null)); // IAE
// after
List<Interval> clean = intervals.stream().filter(Objects::nonNull).collect(Collectors.toList());
JodaUtils.mergeIntervals(clean);
Defensive patterns

Strategy: validation

Validate before calling

List<Interval> nonNull = intervals.stream().filter(Objects::nonNull).collect(Collectors.toList());
if (nonNull.size() != intervals.size()) {
  log.warn("Dropped %d null intervals", intervals.size() - nonNull.size());
}

Type guard

static boolean hasNoNullIntervals(List<Interval> list) {
  return list.stream().allMatch(Objects::nonNull);
}

Try / catch

try {
  return JodaUtils.mergeIntervals(intervals);
} catch (IllegalArgumentException e) {
  throw new IllegalStateException("interval list contains null elements", e);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/4a10c404f2e9f7a6. Report an issue: GitHub.

Appendix: source

Thrown at processing/src/main/java/org/apache/druid/java/util/common/JodaUtils.java:126

    {
      private Interval previous;

      @Override
      public boolean hasNext()
      {
        return peekingIterator.hasNext();
      }

      @Override
      public Interval next()
      {
        if (!hasNext()) {
          throw new NoSuchElementException();
        }

        Interval currInterval = peekingIterator.next();
        if (currInterval == null) {
          throw new IAE("Element of intervals is null");
        }

        // check sorted ascending:
        verifyAscendingSortOrder(previous, currInterval);

        previous = currInterval;

        while (hasNext()) {
          Interval next = peekingIterator.peek();
          if (next == null) {
            throw new IAE("Element of intervals is null");
          }

          if (currInterval.abuts(next)) {
            currInterval = new Interval(currInterval.getStart(), next.getEnd());
            peekingIterator.next();
          } else if (currInterval.overlaps(next)) {
            DateTime nextEnd = next.getEnd();

View on GitHub (pinned to 9b90983fd2)