apache/hadoop · error · IllegalArgumentException
This method can only be called from within a Job
Error message
This method can only be called from within a Job
What it means
Error "This method can only be called from within a Job" thrown in apache/hadoop.
Source
Thrown at hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/FileOutputFormat.java:285
* Helper function to generate a name that is unique for the task.
*
* <p>The generated name can be used to create custom files from within the
* different tasks for the job, the names for different tasks will not collide
* with each other.</p>
*
* <p>The given name is postfixed with the task type, 'm' for maps, 'r' for
* reduces and the task partition number. For example, give a name 'test'
* running on the first map o the job the generated name will be
* 'test-m-00000'.</p>
*
* @param conf the configuration for the job.
* @param name the name to make unique.
* @return a unique name accross all tasks of the job.
*/
public static String getUniqueName(JobConf conf, String name) {
int partition = conf.getInt(JobContext.TASK_PARTITION, -1);
if (partition == -1) {
throw new IllegalArgumentException(
"This method can only be called from within a Job");
}
String taskType = conf.getBoolean(JobContext.TASK_ISMAP,
JobContext.DEFAULT_TASK_ISMAP) ? "m" : "r";
NumberFormat numberFormat = NumberFormat.getInstance();
numberFormat.setMinimumIntegerDigits(5);
numberFormat.setGroupingUsed(false);
return name + "-" + taskType + "-" + numberFormat.format(partition);
}
/**
* Helper function to generate a {@link Path} for a file that is unique for
* the task within the job output directory.
*
* <p>The path can be used to create custom files from within the map andView on GitHub (pinned to 2add963021)
Solutions
- Call this API only from a running task attempt (mapper/reducer) where a Job context exists, not from the client driver or external code.
When it happens
Trigger: Thrown at hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/FileOutputFormat.java:285 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/96c7900dc014f3ec.
Report an issue: GitHub.