java-native-access/jna · error · UnsupportedOperationException
remove
Error message
remove
What it means
IComEnumVariantIterator implements Iterator purely so an IEnumVARIANT can be used in for-each loops, but the underlying enumeration cannot remove elements. Calling remove() throws UnsupportedOperationException with message "remove".
Source
Thrown at contrib/platform/src/com/sun/jna/platform/win32/COM/IComEnumVariantIterator.java:134
backingIteration.Release();
backingIteration = null;
}
}
@Override
protected void finalize() throws Throwable {
close();
super.finalize();
}
@Override
public Iterator<Variant.VARIANT> iterator() {
return this;
}
@Override
public void remove() {
throw new UnsupportedOperationException("remove");
}
}
View on GitHub (pinned to d036ad9781)
Solutions
- Do not call remove(); collect the items into a list and remove them from that list instead.
- Use the plain IEnumVARIANT.Next/Reset/Skip APIs directly if mutation of the enumeration is needed.
- Wrap the loop and catch UnsupportedOperationException if generic code might call remove.
Example fix
// before
for (Variant.VARIANT v : iter) { iter.remove(); }
// after
List<Variant.VARIANT> items = new ArrayList<>();
for (Variant.VARIANT v : iter) { items.add(v); }
items.remove(items.size() - 1); Defensive patterns
Strategy: try-catch
Try / catch
for (Variant.VARIANT v : comEnumVariantIterator) {
// never call remove() here; UnsupportedOperationException is guaranteed
} Prevention
- Treat IComEnumVariantIterator as read-only
- Never pass it to code that removes while iterating
- Copy elements into a List if mutation is needed
When it happens
Trigger: Invoking Iterator.remove() (explicitly or implicitly through any collection adapter) on the iterator obtained from an IComEnumVariantIterator.
Common situations: Generic code that removes items while iterating a Collection/Iterable; refactoring code that assumed a mutable iterator.
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
- remove
- Output directory NOT sucessfully created to: <comRootDir>
- Commandline parameter not found: <key>
- advise: Interface must define a value for either iid via the
- ComInterface must define a value for iid
AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12).
Data as JSON: /api/errors/db0268484a56a8ee.
Report an issue: GitHub.