apache/pulsar · warning · IllegalArgumentException
Current size and other size not equals
Error message
Current size and other size not equals
What it means
MultiMessageIdImpl.compareTo requires both multi-ids to cover the same number of topics/partitions; if either map is null or their sizes differ it throws IllegalArgumentException('Current size and other size not equals'). A position across partitions can only be ordered element-wise when the partition sets match.
Source
Thrown at pulsar-client/src/main/java/org/apache/pulsar/client/impl/MultiMessageIdImpl.java:69
}
// If all messageId in map are same size, and all bigger/smaller than the other, return valid value.
@Override
public int compareTo(MessageId o) {
if (!(o instanceof MultiMessageIdImpl)) {
throw new IllegalArgumentException(
"expected MultiMessageIdImpl object. Got instance of " + o.getClass().getName());
}
MultiMessageIdImpl other = (MultiMessageIdImpl) o;
Map<String, MessageId> otherMap = other.getMap();
if ((map == null || map.isEmpty()) && (otherMap == null || otherMap.isEmpty())) {
return 0;
}
if (otherMap == null || map == null || otherMap.size() != map.size()) {
throw new IllegalArgumentException("Current size and other size not equals");
}
int result = 0;
for (Entry<String, MessageId> entry : map.entrySet()) {
MessageId otherMessage = otherMap.get(entry.getKey());
if (otherMessage == null) {
throw new IllegalArgumentException(
"Other MessageId not have topic " + entry.getKey());
}
int currentResult = entry.getValue().compareTo(otherMessage);
if (result == 0) {
result = currentResult;
} else if (currentResult == 0) {
continue;
} else if (result != currentResult) {
throw new IllegalArgumentException(
"Different MessageId in Map get different compare result");View on GitHub (pinned to 820761864e)
Solutions
- Re-checkpoint cursors after any partition-count change; don't compare cursors taken before/after a partition resize
- Handle the extra partitions explicitly: drop them from the newer cursor or default the missing ones to earliest/latest before comparing
- If comparing for resume logic, compare only the intersection of topics and treat missing topics as earliest
- Catch IllegalArgumentException and rebuild the cursor from per-partition state
Example fix
// before
int r = oldCursor.compareTo(newCursor); // throws if partition counts differ
// after
Map<String, MessageId> oldMap = oldCursor.getMap();
Map<String, MessageId> newMap = newCursor.getMap();
if (oldMap.size() != newMap.size()) {
// topic was re-partitioned; rebuild cursor for current partition count
oldMap = rebuildCursorForCurrentPartitions(newMap.keySet());
}
int r = oldCursor.compareTo(newCursor); Defensive patterns
Strategy: validation
Validate before calling
boolean canCompare(MultiMessageIdImpl a, MultiMessageIdImpl b) {
return a.getMap() != null && b.getMap() != null
&& a.getMap().size() == b.getMap().size();
} Type guard
boolean samePartitionCount(MultiMessageIdImpl a, MultiMessageIdImpl b) {
return a.getMap().size() == b.getMap().size();
} Try / catch
try {
int r = a.compareTo(b);
} catch (IllegalArgumentException e) {
// topic re-partitioned: rebuild cursors for the current partition count
} Prevention
- Re-checkpoint cursors after any partition-count change
- Never compare cursors captured before and after a re-partitioning without migration
- Build cursors from the current topic partition list, not from stale stored maps
When it happens
Trigger: Comparing two MultiMessageIdImpl built from different numbers of partitions — typically after the partitioned topic was resized (more partitions added) between the two snapshots, or one snapshot came from an empty/null map.
Common situations: Checkpoint restore after increasing partition count of a partitioned topic; comparing an early empty cursor with a later full one; mixing cursors from differently configured topics.
Related errors
- expected MultiMessageIdImpl object. Got instance of
- Other MessageId not have topic
- Different MessageId in Map get different compare result
- isDuplicated cannot accept
- ResourceGroupCreate: Invalid null ResourceGroup config
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/ef51300b0cd58111.
Report an issue: GitHub.