apache/druid · error · IllegalArgumentException

Expected instance of %s, got %s

Error message

Expected instance of %s, got %s

What it means

SeekableStreamSequenceNumbers.validateSequenceNumbersBaseType ensures that two sequence-numbers objects used in the same operation are of the exact same concrete class (e.g. KafkaSequenceNumbers vs KinesisSequenceNumbers, or start vs end numbers types). If 'other' is an instance of a different class, it throws IllegalArgumentException because offsets/partitions from incompatible stream types cannot be compared or merged.

Source

Thrown at indexing-service/src/main/java/org/apache/druid/indexing/seekablestream/SeekableStreamSequenceNumbers.java:59

   */
  String getStream();

  /**
   * Returns whether the sequence number data is for possibly multiple streams / topics.
   */
  default boolean isMultiTopicPartition()
  {
    return false;
  }

  /**
   * throws exception if this class and other class are not equal
   * @param other the other instance to compare.
   */
  default void validateSequenceNumbersBaseType(SeekableStreamSequenceNumbers<PartitionIdType, SequenceOffsetType> other)
  {
    if (this.getClass() != other.getClass()) {
      throw new IAE(
          "Expected instance of %s, got %s",
          this.getClass().getName(),
          other.getClass().getName()
      );
    }
  }

  /**
   * Returns a map of partitionId -> sequenceNumber.
   */
  Map<PartitionIdType, SequenceOffsetType> getPartitionSequenceNumberMap();

  /**
   * Merges this and the given other and returns the merged result.
   *
   * @see DataSourceMetadata#plus
   */
  SeekableStreamSequenceNumbers<PartitionIdType, SequenceOffsetType> plus(

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Use the correct SequenceNumbers factory for the stream type (KafkaSequenceNumbers.of / KinesisSequenceNumbers.of) for both start and end sequence numbers.
  2. Ensure the supervisor spec's ioConfig.sequenceNumbers objects all come from the same streaming platform as the task type.
  3. If writing custom code, check the concrete class (e.g. instanceof KafkaSequenceNumbers) before calling methods that validate equality against another sequence numbers object.
  4. Fix any spec template/serialization that silently drops the platform-specific subtype during JSON round-trips.

Example fix

// before: mixing types
SeekableStreamSequenceNumbers<?, ?> start = KinesisSequenceNumbers.of(...);
SeekableStreamSequenceNumbers<?, ?> end = KafkaSequenceNumbers.of(...);
start.validateEqualPartitionOffsets(end);
// after: use matching types
KafkaSequenceNumbers<?> start = KafkaSequenceNumbers.of(...);
KafkaSequenceNumbers<?> end = KafkaSequenceNumbers.of(...);
start.validateEqualPartitionOffsets(end);
Defensive patterns

Strategy: type-guard

Type guard

if (start.getClass() != end.getClass()) { throw new IllegalArgumentException("sequence numbers from different stream types"); } // or: require KafkaSequenceNumbers start/end both before calling validateEqualPartitionOffsets

Try / catch

try { start.validateEqualPartitionOffsets(end); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("Expected instance of")) { rebuildSequenceNumbersForStreamType(); } else { throw e; } }

Prevention

When it happens

Trigger: Comparing or composing SeekableStreamSequenceNumbers where this.getClass() != other.getClass() — e.g. mixing KafkaSequenceNumbers with KinesisSequenceNumbers, or a supervisor/task passing an end-sequence-numbers object of a different stream type into validateEqualPartitionOffsets.

Common situations: Copying a supervisor spec from Kafka to Kinesis without changing the sequenceNumbers class; programmatically constructing sequence numbers with the wrong generic types; submitting an ioConfig where start/end sequence numbers were built by different stream implementations.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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