{"record":{"id":"79ed20847514c838","repo":"apache/druid","slug":"cannot-compare-against-something-that-is-not-a-str","errorCode":null,"errorMessage":"Cannot compare against something that is not a StringPartitionChunk.","messagePattern":"Cannot compare against something that is not a StringPartitionChunk\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/timeline/partition/StringPartitionChunk.java","lineNumber":108,"sourceCode":"  {\n    return end == null;\n  }\n\n  @Override\n  public int getChunkNumber()\n  {\n    return chunkNumber;\n  }\n\n  @Override\n  public int compareTo(PartitionChunk<T> chunk)\n  {\n    if (chunk instanceof StringPartitionChunk) {\n      StringPartitionChunk<T> stringChunk = (StringPartitionChunk<T>) chunk;\n\n      return Integer.compare(chunkNumber, stringChunk.chunkNumber);\n    }\n    throw new IllegalArgumentException(\"Cannot compare against something that is not a StringPartitionChunk.\");\n  }\n\n  @Override\n  @SuppressWarnings(\"unchecked\")\n  public boolean equals(Object o)\n  {\n    if (this == o) {\n      return true;\n    }\n    if (o == null || getClass() != o.getClass()) {\n      return false;\n    }\n\n    return compareTo((StringPartitionChunk<T>) o) == 0;\n  }\n\n  @Override\n  public int hashCode()","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/timeline/partition/StringPartitionChunk.java#L90-L126","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Only compare chunks of the same concrete type; check chunk.getClass() or instanceof before calling compareTo","If tombstones must coexist, use a comparison strategy that handles mixed types (e.g. TombstonePartitionedChunk which defines compareTo for its own case) before dispatching","Ensure partition sets are built homogeneously — don't add tombstone and StringPartitionChunk entries to the same partition slot","Update code that relied on equals/compareTo across chunk types to use explicit type checks"],"exampleFix":"// before\nboolean same = stringChunk.equals(tombstoneChunk); // throws via compareTo\n// after\nboolean same = stringChunk.getClass() == tombstoneChunk.getClass()\n    && stringChunk.equals(tombstoneChunk);","handlingStrategy":"type-guard","validationCode":"if (!(chunk instanceof StringPartitionChunk)) {\n  throw new IllegalArgumentException(\"Expected StringPartitionChunk\");\n}","typeGuard":"static <T> boolean isStringPartitionChunk(PartitionChunk<T> c) {\n  return c instanceof StringPartitionChunk;\n}","tryCatchPattern":"try {\n  int cmp = chunk.compareTo(other);\n} catch (IllegalArgumentException e) {\n  // fall back to type-aware comparison\n}","preventionTips":["Keep partition sets homogeneous in chunk type","Never mix tombstone and data chunks in one sorted collection","Check classes before equality/comparison in timeline code"],"tags":["java","illegal-argument","comparison","partition-chunks"],"backgroundTag":"invalid-argument-value","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"}