{"record":{"id":"213694459d2ee175","repo":"apache/hadoop","slug":"remove-not-implemented-213694","errorCode":null,"errorMessage":"remove not implemented","messagePattern":"remove not implemented","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/task/ReduceContextImpl.java","lineNumber":251,"sourceCode":"      // can't advance it here.\n      if (!nextKeyIsSame) {\n        throw new NoSuchElementException(\"iterate past last value\");\n      }\n      // otherwise, go to the next key/value pair\n      try {\n        nextKeyValue();\n        return value;\n      } catch (IOException ie) {\n        throw new RuntimeException(\"next value iterator failed\", ie);\n      } catch (InterruptedException ie) {\n        // this is bad, but we can't modify the exception list of java.util\n        throw new RuntimeException(\"next value iterator interrupted\", ie);        \n      }\n    }\n\n    @Override\n    public void remove() {\n      throw new UnsupportedOperationException(\"remove not implemented\");\n    }\n\n    @Override\n    public void mark() throws IOException {\n      if (getBackupStore() == null) {\n        backupStore = new BackupStore<KEYIN,VALUEIN>(conf, taskid);\n      }\n      isMarked = true;\n      if (!inReset) {\n        backupStore.reinitialize();\n        if (currentKeyLength == -1) {\n          // The user has not called next() for this iterator yet, so\n          // there is no current record to mark and copy to backup store.\n          return;\n        }\n        assert (currentValueLength != -1);\n        int requestedSize = currentKeyLength + currentValueLength + \n          WritableUtils.getVIntSize(currentKeyLength) +","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/task/ReduceContextImpl.java#L233-L269","documentation":"ValueIterator.remove() unconditionally throws UnsupportedOperationException. The reduce input is a streamed view over shuffle output and is read-only by design; there is nothing to remove mid-iteration.","triggerScenarios":"Reducer code calls context.getValues().iterator().remove(); a library adapting the values iterator to another API invokes remove() as part of its contract.","commonSituations":"Porting collection-based code to a reducer; using collection helpers (Guava, Streams) that call remove() when filtering; wrapping the iterator in a class expecting a mutable ListIterator.","solutions":["Delete the remove() call and filter values inside the loop instead","When handing the iterator to an API that may call remove(), wrap it with an adapter whose remove() is a no-op","Model exclusion by collecting keys/offsets to skip, not by mutating the stream"],"exampleFix":"// before\nIterator<VALUEIN> it = context.getValues().iterator();\nit.next();\nit.remove();\n// after: filter instead of remove\nwhile (it.hasNext()) {\n  VALUEIN v = it.next();\n  if (!skip(v)) { context.write(key, v); }\n}","handlingStrategy":"validation","validationCode":"if (iteratorHasRemove(it)) { /* refuse to adapt remove() */ }","typeGuard":"static Iterator<VALUEIN> readOnly(final Iterator<VALUEIN> it) {\n  return new Iterator<VALUEIN>() {\n    @Override public boolean hasNext() { return it.hasNext(); }\n    @Override public VALUEIN next() { return it.next(); }\n    @Override public void remove() { /* no-op: reduce stream is read-only */ }\n  };\n}","tryCatchPattern":"try {\n  it.remove();\n} catch (UnsupportedOperationException e) {\n  log.warn(\"Values iterator does not support remove; filtering instead\");\n}","preventionTips":["Treat the reduce input as a stream, not a collection","Filter with an if inside the loop rather than mutating the iterator","Wrap the iterator defensively before passing it to third-party helpers"],"tags":["mapreduce","reducer","iterator","api-misuse","read-only"],"backgroundTag":"unsupported-operation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}