{"record":{"id":"96c7900dc014f3ec","repo":"apache/hadoop","slug":"this-method-can-only-be-called-from-within-a-job","errorCode":null,"errorMessage":"This method can only be called from within a Job","messagePattern":"This method can only be called from within a Job","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/FileOutputFormat.java","lineNumber":285,"sourceCode":"   * Helper function to generate a name that is unique for the task.\n   *\n   * <p>The generated name can be used to create custom files from within the\n   * different tasks for the job, the names for different tasks will not collide\n   * with each other.</p>\n   *\n   * <p>The given name is postfixed with the task type, 'm' for maps, 'r' for\n   * reduces and the task partition number. For example, give a name 'test'\n   * running on the first map o the job the generated name will be\n   * 'test-m-00000'.</p>\n   *\n   * @param conf the configuration for the job.\n   * @param name the name to make unique.\n   * @return a unique name accross all tasks of the job.\n   */\n  public static String getUniqueName(JobConf conf, String name) {\n    int partition = conf.getInt(JobContext.TASK_PARTITION, -1);\n    if (partition == -1) {\n      throw new IllegalArgumentException(\n        \"This method can only be called from within a Job\");\n    }\n\n    String taskType = conf.getBoolean(JobContext.TASK_ISMAP,\n        JobContext.DEFAULT_TASK_ISMAP) ? \"m\" : \"r\";\n\n    NumberFormat numberFormat = NumberFormat.getInstance();\n    numberFormat.setMinimumIntegerDigits(5);\n    numberFormat.setGroupingUsed(false);\n\n    return name + \"-\" + taskType + \"-\" + numberFormat.format(partition);\n  }\n\n  /**\n   * Helper function to generate a {@link Path} for a file that is unique for\n   * the task within the job output directory.\n   *\n   * <p>The path can be used to create custom files from within the map and","sourceCodeStart":267,"sourceCodeEnd":303,"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/FileOutputFormat.java#L267-L303","documentation":"Error \"This method can only be called from within a Job\" thrown in apache/hadoop.","triggerScenarios":"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.","commonSituations":"See trigger scenarios.","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."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}