{"record":{"id":"59602c3310679af5","repo":"elastic/elasticsearch","slug":"failed-to-create-output-directory","errorCode":null,"errorMessage":"Failed to create output directory","messagePattern":"Failed to create output directory","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ExtractForeignApiTask.java","lineNumber":156,"sourceCode":"\n    /**\n     * Extraction logic that executes inside the forked JDK 21 worker process.\n     * Reads {@code java.lang.foreign} classes from the worker's own {@code jrt:/} image, so there\n     * are no cross-JDK module-format compatibility concerns.\n     */\n    public abstract static class ExtractionWorkAction implements WorkAction<ExtractionParameters> {\n\n        private static final Logger LOGGER = Logging.getLogger(ExtractionWorkAction.class);\n\n        @Override\n        public void execute() {\n            checkRuntimeJava21();\n\n            Path outputPath = getParameters().getOutputJar().getAsFile().get().toPath();\n            try {\n                Files.createDirectories(outputPath.getParent());\n            } catch (IOException e) {\n                throw new UncheckedIOException(\"Failed to create output directory\", e);\n            }\n\n            FileSystem jrtFs = FileSystems.getFileSystem(URI.create(\"jrt:/\"));\n            Path foreignRoot = jrtFs.getPath(\"modules\", \"java.base\", \"java\", \"lang\", \"foreign\");\n\n            int count = 0;\n            try (\n                JarOutputStream jar = new JarOutputStream(Files.newOutputStream(outputPath));\n                Stream<Path> walk = Files.walk(foreignRoot)\n            ) {\n                for (Path file : (Iterable<Path>) walk::iterator) {\n                    if (Files.isRegularFile(file) == false || file.getFileName().toString().endsWith(\".class\") == false) {\n                        continue;\n                    }\n                    byte[] stubBytes;\n                    try (InputStream is = Files.newInputStream(file)) {\n                        stubBytes = createStub(is);\n                    }","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ExtractForeignApiTask.java#L138-L174","documentation":"Thrown by ExtractForeignApiTask.ExtractionWorkAction.execute when Files.createDirectories(outputPath.getParent()) fails with IOException, wrapped as UncheckedIOException. The worker extracts java.lang.foreign classes from the running JDK's jrt:/ image into an output jar, so it first needs the output jar's parent directory to exist.","triggerScenarios":"The configured outputJar path has a parent that cannot be created - invalid path, permission denied, or a parent component names an existing non-directory file.","commonSituations":"outputJar property misconfigured to an unwritable or invalid path; build output dir on read-only filesystem; stale file occupying the parent path.","solutions":["Check the outputJar task property resolves to a writable, valid path.","Ensure no regular file occupies the intended parent directory.","Verify write permissions on the build output root.","Clean the build outputs so stale files are removed."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"Path parent = getParameters().getOutputJar().getAsFile().get().toPath().getParent();\nif (Files.exists(parent) == false && parent != null) {\n    // will attempt createDirectories; check writability of nearest existing ancestor\n    Path ancestor = parent;\n    while (ancestor != null && Files.exists(ancestor) == false) ancestor = ancestor.getParent();\n    if (ancestor != null && Files.isWritable(ancestor) == false) {\n        throw new UncheckedIOException(\"Cannot create output directory \" + parent, new IOException(\"not writable\"));\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    Files.createDirectories(outputPath.getParent());\n} catch (IOException e) {\n    throw new UncheckedIOException(\"Failed to create output directory\", e);\n}","preventionTips":["Configure outputJar to a writable, valid path.","Ensure no regular file occupies the intended parent directory.","Clean build outputs so stale files do not block directory creation."],"tags":["gradle","io","worker","jrt","build-tools"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}