{"record":{"id":"89fc6a46aeb82a2e","repo":"apache/flink","slug":"remove-not-supported","errorCode":null,"errorMessage":"Remove not supported","messagePattern":"Remove not supported","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/util/NetUtils.java","lineNumber":474,"sourceCode":"                                    + range);\n                }\n                rangeIterator =\n                        new Iterator<Integer>() {\n                            int i = start;\n\n                            @Override\n                            public boolean hasNext() {\n                                return i <= end;\n                            }\n\n                            @Override\n                            public Integer next() {\n                                return i++;\n                            }\n\n                            @Override\n                            public void remove() {\n                                throw new UnsupportedOperationException(\"Remove not supported\");\n                            }\n                        };\n            }\n            iterators.add(rangeIterator);\n        }\n\n        return iterators;\n    }\n\n    /**\n     * Tries to allocate a socket from the given sets of ports.\n     *\n     * @param portsIterator A set of ports to choose from.\n     * @param factory A factory for creating the SocketServer\n     * @return null if no port was available or an allocated socket.\n     */\n    public static ServerSocket createSocketFromPorts(\n            Iterator<Integer> portsIterator, SocketFactory factory) {","sourceCodeStart":456,"sourceCodeEnd":492,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/util/NetUtils.java#L456-L492","documentation":"The anonymous Iterator<Integer> that NetUtils.getPortRangeFromString creates for a 'start-end' range implements remove() as UnsupportedOperationException. The port-range iterator is read-only by design. Flink code itself only iterates; this surfaces when user code holds the iterator and calls remove().","triggerScenarios":"Calling .remove() on the Iterator obtained from NetUtils.getPortRangeFromString or PortRange.getPortsIterator() while trying to prune candidate ports.","commonSituations":"Generic iterator-manipulation utility applied to the port iterator; port-selection code adapted from a mutable-list implementation.","solutions":["Do not mutate the port iterator; collect ports into a list and filter that instead.","If you need to skip ports, maintain your own Set of used ports and check membership while iterating."],"exampleFix":"// before\nIterator<Integer> it = new PortRange(range).getPortsIterator();\nit.next();\nit.remove(); // throws\n\n// after\nList<Integer> ports = new ArrayList<>();\nnew PortRange(range).getPortsIterator().forEachRemaining(ports::add);\nports.removeIf(p -> p == skipPort);","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat the port iterator as read-only.","Copy ports into your own collection before filtering/removing."],"tags":["iterator","ports","api-misuse","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}