apache/druid · error · UnsupportedOperationException
Cannot retainAll ona an IntegerSet
Error message
Cannot retainAll ona an IntegerSet
What it means
retainAll is intentionally unimplemented in IntegerSet; it is a stub that always throws UnsupportedOperationException. The message contains a typo ('ona an') but the semantics are simply that intersection-based removal is not supported by this class.
Source
Thrown at processing/src/main/java/org/apache/druid/collections/IntegerSet.java:145
@Override
public boolean addAll(Collection<? extends Integer> c)
{
boolean setChanged = false;
for (Integer i : c) {
if (!this.contains(i)) {
setChanged = true;
this.add(i);
}
}
return setChanged;
}
@Override
public boolean retainAll(Collection<?> c)
{
// Stub
throw new UnsupportedOperationException("Cannot retainAll ona an IntegerSet");
}
@Override
public boolean removeAll(Collection<?> c)
{
Iterator<?> it = c.iterator();
boolean changed = false;
while (it.hasNext()) {
Integer val = (Integer) it.next();
changed = remove(val) || changed;
}
return changed;
}
@Override
public void clear()
{
mutableBitmap.clear();View on GitHub (pinned to 9b90983fd2)
Solutions
- Implement intersection manually: iterate the set and remove elements not in the other collection via iterator.remove() with contains() checks — note removeAll IS supported
- Copy to a HashSet<Integer>, perform retainAll there, then clear() and addAll() back into the IntegerSet
- Build a new IntegerSet containing only elements that pass contains() on the other collection
- If retainAll is core to your logic, use HashSet<Integer> instead of IntegerSet
Example fix
// before integerSet.retainAll(keep); // UnsupportedOperationException // after integerSet.removeIf(v -> !keep.contains(v)); // removeIf uses remove(), which is supported
Defensive patterns
Strategy: fallback
Try / catch
try { set.retainAll(keep); } catch (UnsupportedOperationException e) { set.removeIf(v -> !keep.contains(v)); } Prevention
- Never rely on optional Set operations on IntegerSet
- Use removeIf (backed by the supported remove()) for intersection
- Keep IntegerSet usage narrow; do full set algebra in HashSet
When it happens
Trigger: Any call to retainAll(collection) on an IntegerSet, e.g. keeping only the elements present in another collection.
Common situations: Code written generically against the Set interface (or refactored to use IntegerSet where a HashSet was before) that relies on retainAll for set intersection.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Reverse lookup not allowed.
- Serialization not supported here
- Map column doesn't support getRow()
- Map column doesn't support lookupName()
- Map column doesn't support idLookup()
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/67a64b8dd0c1e272.
Report an issue: GitHub.