apache/pulsar · warning · UnsupportedOperationException
UnsupportedOperationException
Error message
UnsupportedOperationException
What it means
LongPairRangeSet.toRanges(int) is a default interface method that throws UnsupportedOperationException; only implementations that support exporting ranges (e.g. RangeSetLongPairStore-backed ones) override it. Calling it on a non-supporting implementation fails.
Source
Thrown at pulsar-common/src/main/java/org/apache/pulsar/common/util/collections/LongPairRangeSet.java:141
*/
int size();
/**
* It returns very first smallest range in the rangeSet.
*
* @return first smallest range into the set
*/
Range<T> firstRange();
/**
* It returns very last biggest range in the rangeSet.
*
* @return last biggest range into the set
*/
Range<T> lastRange();
default Map<Long, long[]> toRanges(int maxRanges) {
throw new UnsupportedOperationException();
}
/**
* Build {@link LongPairRangeSet} using internal ranges returned by {@link #toRanges(int)} .
*
* @param ranges
*/
default void build(Map<Long, long[]> ranges) {
throw new UnsupportedOperationException();
}
/**
* Return the number bit sets to true from lower (inclusive) to upper (inclusive).
*/
int cardinality(long lowerKey, long lowerValue, long upperKey, long upperValue);
/**
* Represents a function that accepts two long arguments and produces a result.View on GitHub (pinned to 820761864e)
Solutions
- Use an implementation that overrides toRanges (e.g. the NavigableSet-backed RangeSetLongPairStore implementation)
- Check concrete type before calling and provide an alternative path
- Implement toRanges in your custom LongPairRangeSet implementation
Example fix
// before
Map<Long, long[]> ranges = longPairSet.toRanges(maxRanges); // may throw
// after
if (longPairSet instanceof RangeSetLongPairStore) {
Map<Long, long[]> ranges = longPairSet.toRanges(maxRanges);
} else {
// fallback: iterate individual ranges via ranges()/lastRange()
} Defensive patterns
Strategy: try-catch
Validate before calling
static boolean supportsRangeExport(LongPairRangeSet<?> set) {
return !(set.getClass().getSimpleName().equals("LongPairRangeSet") ); // must be an overriding impl
} Type guard
static boolean supportsToRanges(LongPairRangeSet<?> set) {
return set instanceof RangeSetLongPairStore; // implementation known to override toRanges
} Try / catch
try {
Map<Long, long[]> ranges = set.toRanges(maxRanges);
} catch (UnsupportedOperationException e) {
// fall back to iterating ranges()/individual entries
} Prevention
- Read interface default methods: UnsupportedOperationException default means opt-in feature
- Use implementations known to support toRanges for persistence/export paths
- Add tests covering toRanges for every custom LongPairRangeSet implementation
When it happens
Trigger: Calling toRanges(maxRanges) on a LongPairRangeSet implementation that does not override the default (custom or legacy implementation).
Common situations: Persistence/serialization code or topic-level range export calling toRanges generically on any LongPairRangeSet without knowing the concrete type.
Related errors
- Expire message by timestamp is not supported for non-persist
- Expire message by position is not supported for non-persiste
- PublishTxnMessage is not supported by non-persistent topic
- Receiver queue size can't be changed in ZeroQueueConsumerImp
- stream is not supported
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/75a521dd86bafd64.
Report an issue: GitHub.