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

  1. Use an implementation that overrides toRanges (e.g. the NavigableSet-backed RangeSetLongPairStore implementation)
  2. Check concrete type before calling and provide an alternative path
  3. 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

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


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/75a521dd86bafd64. Report an issue: GitHub.