{"record":{"id":"c292a54cfadba353","repo":"jwtk/jjwt","slug":"not-supported","errorCode":null,"errorMessage":"Not supported","messagePattern":"Not supported","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/io/jsonwebtoken/lang/Collections.java","lineNumber":569,"sourceCode":"     */\n    private static class EnumerationIterator<E> implements Iterator<E> {\n\n        private final Enumeration<E> enumeration;\n\n        public EnumerationIterator(Enumeration<E> enumeration) {\n            this.enumeration = enumeration;\n        }\n\n        public boolean hasNext() {\n            return this.enumeration.hasMoreElements();\n        }\n\n        public E next() {\n            return this.enumeration.nextElement();\n        }\n\n        public void remove() throws UnsupportedOperationException {\n            throw new UnsupportedOperationException(\"Not supported\");\n        }\n    }\n}\n\n","sourceCodeStart":551,"sourceCodeEnd":574,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/api/src/main/java/io/jsonwebtoken/lang/Collections.java#L551-L574","documentation":"UnsupportedOperationException thrown by the remove() method of the EnumerationIterator adapter in io.jsonwebtoken.lang.Collections. The iterator wraps an Enumeration, which has no removal capability, so remove is intentionally unsupported — calling it always throws.","triggerScenarios":"Calling Iterator.remove() on an iterator obtained by iterating over an Enumeration (e.g. java.util.Collections.list(enumeration)-style adapters or Collections.asIterator/enumeration-wrapped loops), then attempting to remove the current element.","commonSituations":"Generic code that removes elements while iterating (fail-fast pattern) being fed an Enumeration-backed iterator; refactored loops that assumed a modifiable collection; passing enumeration-based iterators into APIs that try to remove.","solutions":["Copy the Enumeration into a real collection first (e.g. Collections.list(enumeration)) and iterate/remove on that","Avoid calling remove(); filter elements into a new collection instead of mutating during iteration","If removal is required, obtain a true collection iterator rather than an Enumeration adapter"],"exampleFix":"// before\nIterator<String> it = Collections.asIterator(enumeration);\nit.next();\nit.remove(); // throws UnsupportedOperationException\n// after\nList<String> list = Collections.list(enumeration);\nIterator<String> it = list.iterator();\nit.next();\nit.remove(); // works","handlingStrategy":"type-guard","validationCode":"Iterator<E> it = ...;\nif (!(it instanceof java.util.ListIterator) && isEnumerationBacked(it)) {\n    it = Collections.list(enumeration).iterator(); // swap to a removable iterator\n}","typeGuard":"static <E> boolean supportsRemove(Iterator<E> it) {\n    try {\n        it.getClass().getDeclaredMethod(\"remove\");\n        return !(it.getClass().getName().contains(\"Enumeration\"));\n    } catch (NoSuchMethodException e) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    it.remove();\n} catch (UnsupportedOperationException e) {\n    // enumeration-backed iterator; rebuild as a modifiable collection and retry\n    List<E> list = new ArrayList<>();\n    it.forEachRemaining(list::add);\n    list.remove(list.size() - 1);\n}","preventionTips":["Convert Enumerations to Lists (Collections.list) before iterative removal","Do not assume Iterator.remove is supported; check documentation or UnsupportedOperationException semantics","Prefer modern Collection APIs over legacy Enumeration in new code"],"tags":["unsupported-operation","iterator","enumeration"],"backgroundTag":"unsupported-operation","analyzedSha":"fb71496164c71442d08adec4571d9616ed5e1b8d","analyzedAt":"2026-09-09T00:33:09.982Z","contentChangedAt":"2026-09-09T00:33:09.982Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}