{"record":{"id":"23e753058025f643","repo":"apache/hadoop","slug":"input-only-available-on-map","errorCode":null,"errorMessage":"Input only available on map","messagePattern":"Input only available on map","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/mapred/Task.java","lineNumber":741,"sourceCode":"      if(skipping && SkipBadRecords.COUNTER_GROUP.equals(group) && (\n          SkipBadRecords.COUNTER_MAP_PROCESSED_RECORDS.equals(counter) ||\n          SkipBadRecords.COUNTER_REDUCE_PROCESSED_GROUPS.equals(counter))) {\n        //if application reports the processed records, move the \n        //currentRecStartIndex to the next.\n        //currentRecStartIndex is the start index which has not yet been \n        //finished and is still in task's stomach.\n        for(int i=0;i<amount;i++) {\n          currentRecStartIndex = currentRecIndexIterator.next();\n        }\n      }\n      setProgressFlag();\n    }\n    public void setInputSplit(InputSplit split) {\n      this.split = split;\n    }\n    public InputSplit getInputSplit() throws UnsupportedOperationException {\n      if (split == null) {\n        throw new UnsupportedOperationException(\"Input only available on map\");\n      } else {\n        return split;\n      }\n    }\n\n    /**\n     * exception thrown when the task exceeds some configured limits.\n     */\n    public class TaskLimitException extends IOException {\n      public TaskLimitException(String str) {\n        super(str);\n      }\n    }\n\n    /**\n     * disk limit checker, runs in separate thread when activated.\n     */\n    public class DiskLimitCheck implements Runnable {","sourceCodeStart":723,"sourceCodeEnd":759,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/Task.java#L723-L759","documentation":"In the old MapReduce API, Task.ReporterImpl can carry the job's InputSplit, but the split is only set for map tasks. getInputSplit() throws UnsupportedOperationException when the split field is null — i.e. whenever it is called from a reduce task or before the split was injected. This is the reduce-phase counterpart of the map-only input-split contract.","triggerScenarios":"Calling reporter.getInputSplit() inside reduce(...) or setup(...) of a job whose reduce side receives the same reporter; generic mapper/reducer utilities that query the split regardless of task type; custom InputFormat wiring that forgets reporter.setInputSplit(split).","commonSituations":"Shared setup() code that reads the FileSplit to get the input file name, reused across map and reduce classes; migrating old-API jobs where reduce-side code accidentally inherits map-side logic.","solutions":["Call reporter.getInputSplit() only in map-side code; guard with the task's isMapTask() or conf.getUseNewMapper()/job context.","Pass input metadata (file name, offset) to the reducer via job configuration or the key/value data instead.","In the new API use Context.getInputSplit() inside Mapper.map(), where it is always available."],"exampleFix":"// before\nString file = ((FileSplit) reporter.getInputSplit()).getPath().getName();\n\n// after\nif (isMapPhase) { // e.g. flagged via job conf\n  String file = ((FileSplit) reporter.getInputSplit()).getPath().getName();\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean taskHasInputSplit(Reporter r) {\n  return r != null && r != Reporter.NULL && taskIsMap(conf);\n}\n// inside map(): safe; inside reduce()/cleanup(): never call reporter.getInputSplit()","tryCatchPattern":null,"preventionTips":["Call getInputSplit() only inside map-side code paths.","Move input-file metadata into the job configuration for reduce-side consumers.","Use the new API's Context.getInputSplit() when possible."],"tags":["hadoop","mapreduce","reporter","input-split","unsupported-operation","reduce"],"backgroundTag":"unsupported-operation-on-type","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}