apache/druid · error · IllegalArgumentException

Cannot compare against something that is not a…

Error message

Cannot compare against something that is not a StringPartitionChunk.

What it means

StringPartitionChunk.compareTo only accepts another StringPartitionChunk; comparing against any other PartitionChunk implementation throws this IllegalArgumentException instead of returning an ordering. It is used by chunk-equality/merge logic in the segment timeline, so a mixed chunk type in the same partition slot breaks comparison.

Solutions

  1. Only compare chunks of the same concrete type; check chunk.getClass() or instanceof before calling compareTo
  2. If tombstones must coexist, use a comparison strategy that handles mixed types (e.g. TombstonePartitionedChunk which defines compareTo for its own case) before dispatching
  3. Ensure partition sets are built homogeneously — don't add tombstone and StringPartitionChunk entries to the same partition slot
  4. Update code that relied on equals/compareTo across chunk types to use explicit type checks

Example fix

// before
boolean same = stringChunk.equals(tombstoneChunk); // throws via compareTo
// after
boolean same = stringChunk.getClass() == tombstoneChunk.getClass()
    && stringChunk.equals(tombstoneChunk);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(chunk instanceof StringPartitionChunk)) {
  throw new IllegalArgumentException("Expected StringPartitionChunk");
}

Type guard

static <T> boolean isStringPartitionChunk(PartitionChunk<T> c) {
  return c instanceof StringPartitionChunk;
}

Try / catch

try {
  int cmp = chunk.compareTo(other);
} catch (IllegalArgumentException e) {
  // fall back to type-aware comparison
}

Prevention

When it happens

Trigger: Calling compareTo (directly or via equals, which delegates) with a PartitionChunk of a different implementation, e.g. comparing a StringPartitionChunk against a TombstonePartitionedChunk or a NumberedPartitionChunk in the same partition set.

Common situations: Timeline code mixing tombstone chunks with regular string-partition chunks during segment replacement; custom PartitionChunk implementations passed to timeline merge logic; tests asserting equality across chunk types.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at processing/src/main/java/org/apache/druid/timeline/partition/StringPartitionChunk.java:108

  {
    return end == null;
  }

  @Override
  public int getChunkNumber()
  {
    return chunkNumber;
  }

  @Override
  public int compareTo(PartitionChunk<T> chunk)
  {
    if (chunk instanceof StringPartitionChunk) {
      StringPartitionChunk<T> stringChunk = (StringPartitionChunk<T>) chunk;

      return Integer.compare(chunkNumber, stringChunk.chunkNumber);
    }
    throw new IllegalArgumentException("Cannot compare against something that is not a StringPartitionChunk.");
  }

  @Override
  @SuppressWarnings("unchecked")
  public boolean equals(Object o)
  {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    return compareTo((StringPartitionChunk<T>) o) == 0;
  }

  @Override
  public int hashCode()

View on GitHub (pinned to 9b90983fd2)