{"record":{"id":"1aa668a0e61e3a34","repo":"quarkusio/quarkus","slug":"failed-to-initialize-file-output-writer","errorCode":null,"errorMessage":"Failed to initialize file output writer","messagePattern":"Failed to initialize file output writer","errorType":"exception","errorClass":"MojoExecutionException","httpStatus":null,"severity":"error","filePath":"devtools/maven/src/main/java/io/quarkus/maven/DependencyListMojo.java","lineNumber":144,"sourceCode":"    protected MavenArtifactResolver resolver;\n\n    @Override\n    public void execute() throws MojoExecutionException, MojoFailureException {\n\n        BufferedWriter writer = null;\n        final Consumer<String> log;\n        if (outputFile == null) {\n            log = s -> getLog().info(s);\n        } else {\n            final BufferedWriter bw;\n            try {\n                Files.createDirectories(outputFile.toPath().getParent());\n                final OpenOption[] openOptions = appendOutput && outputFile.exists()\n                        ? new OpenOption[] { StandardOpenOption.APPEND }\n                        : new OpenOption[0];\n                bw = writer = Files.newBufferedWriter(outputFile.toPath(), openOptions);\n            } catch (IOException e) {\n                throw new MojoExecutionException(\"Failed to initialize file output writer\", e);\n            }\n            log = s -> {\n                try {\n                    bw.write(s);\n                    bw.newLine();\n                } catch (IOException e) {\n                    throw new RuntimeException(\"Failed to log the dependency list to a file\", e);\n                }\n            };\n        }\n        try {\n            logDependencies(log);\n        } finally {\n            if (writer != null) {\n                try {\n                    writer.close();\n                } catch (IOException e) {\n                    getLog().debug(\"Failed to close the output file\", e);","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/devtools/maven/src/main/java/io/quarkus/maven/DependencyListMojo.java#L126-L162","documentation":"DependencyListMojo can write the resolved dependency list to a file (outputFile). Before logging, it creates parent directories and opens a BufferedWriter, applying APPEND when appendOutput is set and the file exists. Any IOException while doing so is wrapped in a MojoExecutionException 'Failed to initialize file output writer', aborting the mojo before any dependency output is produced.","triggerScenarios":"Running mvn quarkus:dependency-list (or related goal) with output file configuration where Files.newBufferedWriter or Files.createDirectories throws IOException — e.g. unwritable path, parent path is a file, or disk/permission problems.","commonSituations":"outputFile points to a read-only directory or outside the project; parent path exists as a regular file; running in CI with restricted filesystem permissions; container/user mismatch on mounted volumes; disk full.","solutions":["Check and fix filesystem permissions on the output file's parent directory","Ensure the outputFile path is valid and its parent is a directory, not a file","Free disk space if the disk is full","Point -DoutputFile (or pom configuration) to a writable location"],"exampleFix":"// before\nmvn quarkus:dependency-list -DoutputFile=/root/protected/deps.txt\n// after\nmvn quarkus:dependency-list -DoutputFile=${project.build.directory}/deps.txt","handlingStrategy":"validation","validationCode":"// Pre-check output file writability before running the mojo\njava.nio.file.Path out = java.nio.file.Path.of(outputFile);\njava.nio.file.Path parent = out.toAbsolutePath().getParent();\nif (parent == null || !java.nio.file.Files.isDirectory(parent) && !parent.toFile().mkdirs()) {\n    throw new IllegalStateException(\"Cannot create directory: \" + parent);\n}\nif (!java.nio.file.Files.isWritable(parent)) {\n    throw new IllegalStateException(\"Directory not writable: \" + parent);\n}\nif (java.nio.file.Files.exists(out) && !java.nio.file.Files.isWritable(out)) {\n    throw new IllegalStateException(\"Output file not writable: \" + out);\n}","typeGuard":null,"tryCatchPattern":"try {\n    mvn quarkus:dependency-list -DoutputFile=target/deps.txt;\n} catch (MojoExecutionException e) {\n    if (\"Failed to initialize file output writer\".equals(e.getMessage())) {\n        // inspect e.getCause() (IOException): fix path/permissions and retry\n        Throwable cause = e.getCause();\n    }\n}","preventionTips":["Point output files at ${project.build.directory} which is always writable in a build","Pre-create output directories in CI before running Maven goals","Check filesystem permissions when running Maven inside containers","Monitor disk space in CI environments"],"tags":["maven","io","file-write","build"],"backgroundTag":"file-write-permission-denied","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}