{"id":"d37a963db23a43e3","repo":"junit-team/junit5","slug":"failed-to-create-output-file","errorCode":null,"errorMessage":"Failed to create output file: ","messagePattern":"Failed to create output file: ","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":null,"severity":"error","filePath":"junit-platform-launcher/src/main/java/org/junit/platform/launcher/listeners/OutputDir.java","lineNumber":114,"sourceCode":"\t\tthis.random = random;\n\t}\n\n\tpublic Path toPath() {\n\t\treturn path;\n\t}\n\n\tpublic Path createFile(String prefix, String extension) throws UncheckedIOException {\n\t\tString filename = \"%s-%d.%s\".formatted(prefix, positiveLong(random), extension);\n\t\tPath outputFile = path.resolve(filename);\n\n\t\ttry {\n\t\t\tif (Files.exists(outputFile)) {\n\t\t\t\tFiles.delete(outputFile);\n\t\t\t}\n\t\t\treturn Files.createFile(outputFile);\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new UncheckedIOException(\"Failed to create output file: \" + outputFile, e);\n\t\t}\n\t}\n\n\tprivate static long positiveLong(SecureRandom random) {\n\t\tvar value = random.nextLong();\n\t\tif (value == Long.MIN_VALUE) {\n\t\t\t// ensure Math.abs returns positive value\n\t\t\tvalue++;\n\t\t}\n\t\treturn Math.abs(value);\n\t}\n\n\t/**\n\t * Determine if the supplied directory contains files with any of the\n\t * supplied extensions.\n\t */\n\tprivate static boolean containsFilesWithExtensions(Path dir, String... extensions) throws IOException {\n\t\tBiPredicate<Path, BasicFileAttributes> matcher = (path, basicFileAttributes) -> {","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/junit-team/junit5/blob/956246301e03d757539f7b76dd5a91f298637563/junit-platform-launcher/src/main/java/org/junit/platform/launcher/listeners/OutputDir.java#L96-L132","documentation":"Thrown by OutputDir.createFile() as an UncheckedIOException when creating a uniquely-named output file fails. The method resolves prefix-random.ext under the output dir, deletes an existing file with that name if present, then calls Files.createFile; any IOException is wrapped with the offending file path in the message.","triggerScenarios":"OutputDir.createFile(prefix, extension) is called when the output directory does not exist, is read-only, the filename collides in an unwritable way, or the filesystem rejects the create. The path is included in the exception message.","commonSituations":"Output directory was deleted between discovery and report writing. Filesystem permissions changed mid-run. Disk full. The output dir was never created because OutputDir.create targeted an invalid path but a downstream component still holds a reference.","solutions":["Ensure the output directory exists and is writable before triggering file creation (set junit.platform.output.dir appropriately).","Check the exception message for the resolved file path and verify its parent directory.","Free disk space / fix permissions on the CI agent.","Avoid concurrent processes writing to the same output dir with non-unique prefixes."],"exampleFix":"// before: output dir deleted mid-run, createFile throws\n\n// after: ensure dir exists and is writable; set a valid output dir\njunit.platform.output.dir = target/test-output","handlingStrategy":"try-catch","validationCode":"Path parent = outputDir.toPath();\nif (!Files.isDirectory(parent) || !Files.isWritable(parent)) {\n    throw new IllegalStateException(\"output dir missing or read-only: \" + parent);\n}","typeGuard":"static boolean canCreateFile(Path dir) {\n    try { Path tmp = Files.createTempFile(dir, \"probe\", \".tmp\"); Files.delete(tmp); return true; }\n    catch (IOException e) { return false; }\n}","tryCatchPattern":"try {\n    outputDir.createFile(prefix, ext);\n} catch (UncheckedIOException e) {\n    // recreate the parent dir or fall back to a temp location\n}","preventionTips":["Ensure the output directory persists and stays writable for the whole run.","Do not clean the output dir between discovery and report writing.","Pre-flight check writability before launching tests."],"tags":["filesystem","output-dir","io","junit-platform"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}