{"record":{"id":"e3f95a74fc5310a8","repo":"stanfordnlp/CoreNLP","slug":"output-path-file-already-exists","errorCode":null,"errorMessage":"Output path ${file} already exists","messagePattern":"Output path (.+?) already exists","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/io/FileSystem.java","lineNumber":143,"sourceCode":"      String error = \"Could not create \" + dir;\n      log.info(error);\n      throw new RuntimeException(error);\n    }\n  }\n\n  public static void checkExistsOrFail(File file) {\n    if (!file.exists()) {\n      String error = \"Output path \" + file + \" does not exist\";\n      log.info(error);\n      throw new RuntimeException(error);\n    }\n  }\n\n  public static void checkNotExistsOrFail(File file) {\n    if (file.exists()) {\n      String error = \"Output path \" + file + \" already exists\";\n      log.info(error);\n      throw new RuntimeException(error);\n    }\n  }\n\n  /**\n   * Unit test code\n   */\n  public static void main(String[] args) {\n    String testDirName = \"FileSystemTest\";\n    String testFileName = \"Pair.java\";\n    \n    File testDir = new File(testDirName);\n    testDir.mkdir();\n    \n    try {\n      copyFile(new File(testFileName),new File(testDirName + \"/\" + testFileName));\n    } catch (RuntimeIOException e) {\n      log.info(\"Copy failed\");\n      System.exit(-1);","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/io/FileSystem.java#L125-L161","documentation":"FileSystem.checkNotExistsOrFail(file) throws RuntimeException if the given file already exists, logging 'Output path <file> already exists'. It protects callers from overwriting prior outputs (and optional overwriting APIs from clobbering data).","triggerScenarios":"Calling checkNotExistsOrFail on a path that is present: rerunning a job without cleaning output, a previous crashed run left partial files, or an output path colliding with an input path.","commonSituations":"Batch jobs restarted without clearing the output directory; timestamps/id collisions in generated filenames; user points --output at an existing file intentionally.","solutions":["Delete or move the existing file/directory first, or pick a fresh output path (timestamp/uuid).","Rerun with output cleanup enabled in your pipeline.","Point the output to a different location and use the overwrite variant if you truly intend replacement.","Check the job that previously wrote there to avoid clobbering needed data."],"exampleFix":"// before\nFileSystem.checkNotExistsOrFail(out); // throws on rerun\n// after\nif (out.exists()) {\n  java.nio.file.Files.move(out.toPath(), out.toPath().resolveSibling(out.getName() + \".bak\"));\n}\nFileSystem.checkNotExistsOrFail(out);","handlingStrategy":"validation","validationCode":"if (file.exists()) {\n  throw new IllegalStateException(\"Output already present, remove or rename: \" + file);\n}","typeGuard":null,"tryCatchPattern":"try {\n  FileSystem.checkNotExistsOrFail(out);\n  runJob(out);\n} catch (RuntimeException e) {\n  log.warning(\"Output exists: \" + e.getMessage());\n}","preventionTips":["Clean output directories between reruns","Generate unique output names (timestamp/uuid)","Never point outputs at input paths"],"tags":["file-io","file-already-exists"],"backgroundTag":"file-already-exists","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}