{"record":{"id":"db0268484a56a8ee","repo":"java-native-access/jna","slug":"remove","errorCode":null,"errorMessage":"remove","messagePattern":"remove","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/win32/COM/IComEnumVariantIterator.java","lineNumber":134,"sourceCode":"            backingIteration.Release();\n            backingIteration = null;\n        }\n    }\n\n    @Override\n    protected void finalize() throws Throwable {\n        close();\n        super.finalize();\n    }\n\n    @Override\n    public Iterator<Variant.VARIANT> iterator() {\n        return this;\n    }\n\n    @Override\n    public void remove() {\n        throw new UnsupportedOperationException(\"remove\");\n    }\n}\n","sourceCodeStart":116,"sourceCodeEnd":137,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/COM/IComEnumVariantIterator.java#L116-L137","documentation":"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\".","triggerScenarios":"Invoking Iterator.remove() (explicitly or implicitly through any collection adapter) on the iterator obtained from an IComEnumVariantIterator.","commonSituations":"Generic code that removes items while iterating a Collection/Iterable; refactoring code that assumed a mutable iterator.","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."],"exampleFix":"// before\nfor (Variant.VARIANT v : iter) { iter.remove(); }\n// after\nList<Variant.VARIANT> items = new ArrayList<>();\nfor (Variant.VARIANT v : iter) { items.add(v); }\nitems.remove(items.size() - 1);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"for (Variant.VARIANT v : comEnumVariantIterator) {\n    // never call remove() here; UnsupportedOperationException is guaranteed\n}","preventionTips":["Treat IComEnumVariantIterator as read-only","Never pass it to code that removes while iterating","Copy elements into a List if mutation is needed"],"tags":["java","iterator","unsupported-operation","com"],"backgroundTag":"unsupported-operation","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}