{"record":{"id":"c6a5b7e519c5e265","repo":"apache/hadoop","slug":"output-directory-already-exists","errorCode":null,"errorMessage":"Output directory {} already exists","messagePattern":"Output directory (.+?) already exists","errorType":"exception","errorClass":"FileAlreadyExistsException","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":131,"sourceCode":"           InvalidJobConfException, IOException {\n    // Ensure that the output directory is set and not already there\n    Path outDir = getOutputPath(job);\n    if (outDir == null && job.getNumReduceTasks() != 0) {\n      throw new InvalidJobConfException(\"Output directory not set in JobConf.\");\n    }\n    if (outDir != null) {\n      FileSystem fs = outDir.getFileSystem(job);\n      // normalize the output directory\n      outDir = fs.makeQualified(outDir);\n      setOutputPath(job, outDir);\n      \n      // get delegation token for the outDir's file system\n      TokenCache.obtainTokensForNamenodes(job.getCredentials(), \n                                          new Path[] {outDir}, job);\n      \n      // check its existence\n      if (fs.exists(outDir)) {\n        throw new FileAlreadyExistsException(\"Output directory \" + outDir + \n                                             \" already exists\");\n      }\n    }\n  }\n\n  /**\n   * Set the {@link Path} of the output directory for the map-reduce job.\n   *\n   * @param conf The configuration of the job.\n   * @param outputDir the {@link Path} of the output directory for \n   * the map-reduce job.\n   */\n  public static void setOutputPath(JobConf conf, Path outputDir) {\n    outputDir = new Path(conf.getWorkingDirectory(), outputDir);\n    conf.set(org.apache.hadoop.mapreduce.lib.output.\n      FileOutputFormat.OUTDIR, outputDir.toString());\n  }\n","sourceCodeStart":113,"sourceCodeEnd":149,"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#L113-L149","documentation":"Error \"Output directory {} already exists\" 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:131 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Delete the existing output directory before rerunning the job, or choose a new, non-existent output path.","If overwriting is intended, remove the directory programmatically in the driver before Job submission."],"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-23T01:17:44.959Z"}