{"record":{"id":"8d7c17875e643fed","repo":"junit-team/junit5","slug":"failed-to-create-output-file-s","errorCode":null,"errorMessage":"Failed to create output file: %s","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/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/listeners/OutputDir.java#L96-L132","documentation":"Thrown as an UncheckedIOException by OutputDir.createFile(prefix, extension) when either Files.delete() on a pre-existing same-named file or Files.createFile() on the generated path fails. The filename is '{prefix}-{randomLong}.{extension}' where the randomLong comes from a SecureRandom, so collisions are essentially impossible — the failure is almost always environmental. This is an INTERNAL API.","triggerScenarios":"Calling outputDir.createFile(...) when the output directory has become read-only between OutputDir creation and the call; the directory was deleted mid-run; the underlying volume is full; on Windows another process (antivirus, search indexer, another fork) holds an exclusive lock on the generated file; the path is on a network filesystem that dropped.","commonSituations":"Antivirus or Windows Defender scanning newly created files and briefly locking them; parallel Gradle/Maven forks writing to the same shared output directory; a CI cleanup job wiping the output dir during the run; an NFS/SMB mount with a transient outage; disk exhaustion during a long test suite.","solutions":["Verify Files.isWritable(outputDir.toPath()) still holds at the point of failure and re-run.","Move the output directory to a local non-network volume (e.g. /tmp or the OS temp dir).","Configure antivirus/search indexer to skip the JUnit output directory.","If using parallel forks, give each fork a distinct output dir via the {uniqueNumber} placeholder in junit.platform.reporting.output.dir."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Before calling createFile, confirm the directory is still writable.\nPath dir = outputDir.toPath();\nif (!Files.isDirectory(dir) || !Files.isWritable(dir)) {\n    throw new IllegalStateException(\"Output directory not writable: \" + dir);\n}","typeGuard":null,"tryCatchPattern":"try {\n    Path report = outputDir.createFile(\"events\", \"xml\");\n} catch (UncheckedIOException e) {\n    // The IOException cause tells you why (read-only, full disk, lock).\n    log.warn(\"Could not create report file in {}\", outputDir.toPath(), e.getCause());\n}","preventionTips":["Place the output directory on a local disk, not a network mount.","Give each parallel fork its own output directory via the {uniqueNumber} placeholder.","Exclude the output directory from antivirus/search-indexer scanning.","Monitor free disk space throughout the run, not just at startup."],"tags":["filesystem","io","reporting","permissions","concurrency"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}