{"id":"b977c81272ff19b8","repo":"junit-team/junit5","slug":"failed-to-create-output-dir","errorCode":null,"errorMessage":"Failed to create output dir","messagePattern":"Failed to create output dir","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":null,"severity":"error","filePath":"junit-platform-launcher/src/main/java/org/junit/platform/launcher/listeners/OutputDir.java","lineNumber":46,"sourceCode":"import org.apiguardian.api.API;\nimport org.junit.platform.commons.util.StringUtils;\n\n@API(status = INTERNAL, since = \"1.9\")\npublic class OutputDir {\n\n\tprivate static final Pattern OUTPUT_DIR_UNIQUE_NUMBER_PLACEHOLDER_PATTERN = Pattern.compile(\n\t\tPattern.quote(OUTPUT_DIR_UNIQUE_NUMBER_PLACEHOLDER));\n\n\tpublic static OutputDir create(Optional<String> customDir) {\n\t\treturn create(customDir, () -> Path.of(\".\"));\n\t}\n\n\tstatic OutputDir create(Optional<String> customDir, Supplier<Path> currentWorkingDir) {\n\t\ttry {\n\t\t\treturn createSafely(customDir, currentWorkingDir);\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new UncheckedIOException(\"Failed to create output dir\", e);\n\t\t}\n\t}\n\n\t/**\n\t * Package private for testing purposes.\n\t */\n\tstatic OutputDir createSafely(Optional<String> customDir, Supplier<Path> currentWorkingDir) throws IOException {\n\t\treturn createSafely(customDir, currentWorkingDir, new SecureRandom());\n\t}\n\n\tprivate static OutputDir createSafely(Optional<String> customDir, Supplier<Path> currentWorkingDir,\n\t\t\tSecureRandom random) throws IOException {\n\t\tPath cwd = currentWorkingDir.get().toAbsolutePath();\n\t\tPath outputDir;\n\n\t\tif (customDir.isPresent() && StringUtils.isNotBlank(customDir.get())) {\n\t\t\toutputDir = cwd.resolve(expandPlaceholders(customDir.get(), random));\n\t\t}","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/junit-team/junit5/blob/956246301e03d757539f7b76dd5a91f298637563/junit-platform-launcher/src/main/java/org/junit/platform/launcher/listeners/OutputDir.java#L28-L64","documentation":"Thrown by OutputDir.create() as an UncheckedIOException when createSafely() hits an IOException creating the output directory. OutputDir resolves a directory from OUTPUT_DIR_PROPERTY_NAME (or defaults to target/build/cwd) and calls Files.createDirectories; any I/O failure (permissions, invalid path, read-only filesystem) is wrapped.","triggerScenarios":"Setting junit.platform.output.dir to a path that cannot be created, or running in a sandbox/container where the default target/ or build/ is not writable. Files.createDirectories throws IOException, caught at OutputDir.create line 45-46.","commonSituations":"CI runner with a read-only working directory. Misconfigured output dir with illegal characters or pointing at a file. Disk full or quota exceeded. Output dir on a network mount that fails metadata operations.","solutions":["Set junit.platform.output.dir (OUTPUT_DIR_PROPERTY_NAME) to a writable, valid path.","Ensure the working directory is writable, or run from the project root where target/build can be created.","Check filesystem permissions and free space on the CI agent.","Avoid using unique-number placeholders that expand into illegal path segments."],"exampleFix":"# before\njunit.platform.output.dir = /opt/readonly/reports\n\n# after\njunit.platform.output.dir = build/test-reports","handlingStrategy":"try-catch","validationCode":"Path dir = Path.of(Optional.ofNullable(System.getProperty(\"junit.platform.output.dir\")).orElse(\"target\"));\nFiles.createDirectories(dir);\nif (!Files.isWritable(dir)) throw new IllegalStateException(\"output dir not writable: \" + dir);","typeGuard":"static boolean isOutputDirWritable(String path) {\n    try { Path p = Path.of(path); Files.createDirectories(p); return Files.isWritable(p); }\n    catch (IOException e) { return false; }\n}","tryCatchPattern":"try {\n    OutputDir.create(Optional.of(path));\n} catch (UncheckedIOException e) {\n    // log, fall back to a known-writable dir, or fail the build\n    throw new RuntimeException(\"Cannot init output dir \" + path, e);\n}","preventionTips":["Point junit.platform.output.dir at a writable, project-local path.","Verify directory writability in CI setup before running tests.","Use the unique-number placeholder to avoid collisions across parallel runs."],"tags":["filesystem","output-dir","configuration","io","junit-platform"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}