{"record":{"id":"23100735cb18bf6c","repo":"oracle/graal","slug":"failed-to-print-the-optimization-log-to-a-file-s","errorCode":null,"errorMessage":"Failed to print the optimization log to a file: %s","messagePattern":"Failed to print the optimization log to a file: (.+?)","errorType":"exception","errorClass":"GraalError","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/OptimizationLogImpl.java","lineNumber":722,"sourceCode":"        }\n        if (printToFile) {\n            try {\n                String pathOptionValue = DebugOptions.OptimizationLogPath.getValue(graph.getOptions());\n                if (pathOptionValue == null) {\n                    pathOptionValue = PathUtilities.getPath(DebugOptions.getDumpDirectory(graph.getOptions()), OPTIMIZATION_LOG_DIRECTORY);\n                }\n                PathUtilities.createDirectories(pathOptionValue);\n                @SuppressWarnings(\"deprecation\")\n                String fileName = IsolateUtil.getIsolateID() + \"_\" + Thread.currentThread().getId();\n                String filePath = PathUtilities.getPath(pathOptionValue, fileName);\n                try (OutputStream outputStream = PathUtilities.openOutputStream(filePath, true);\n                                PrintStream printStream = new PrintStream(outputStream)) {\n                    printStream.print(json);\n                    printStream.print(LINE_SEPARATOR);\n                    printStream.flush();\n                }\n            } catch (IOException exception) {\n                throw new GraalError(\"Failed to print the optimization log to a file: %s\", exception.getMessage());\n            }\n        }\n    }\n\n    /**\n     * Finds and returns the root of the optimization tree.\n     *\n     * @return the root of the optimization tree\n     */\n    public OptimizationPhaseNode findRootPhase() {\n        OptimizationPhaseNode root = currentPhase;\n        while (root.predecessor() != null) {\n            root = (OptimizationPhaseNode) root.predecessor();\n        }\n        assert ROOT_PHASE_NAME.contentEquals(root.getPhaseName()) : \"the found phase must be the root phase\";\n        return root;\n    }\n","sourceCodeStart":704,"sourceCodeEnd":740,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/OptimizationLogImpl.java#L704-L740","documentation":"OptimizationLogImpl.flushToFile writes the accumulated JSON log to OptimizationLogPath (isolate/thread-named file, appended, one JSON per line). Any IOException while creating directories, opening, or writing the stream is wrapped in a GraalError with the underlying message. The error is environmental: the compiler produced the log fine, it just could not persist it.","triggerScenarios":"Enabling the optimization log (e.g., -Dgraal.OptimizationLog=... plus -Dgraal.OptimizationLogPath=DIR) where DIR does not exist and cannot be created, is read-only, the disk is full, or (in sandboxed/containerized runs) the process lacks write permission to that path.","commonSituations":"CI containers running as non-root writing to /graal-dumps; disk-full agents; a relative OptimizationLogPath resolving against an unexpected working directory (e.g., read-only image root in native-image builds); path strings with characters the filesystem rejects.","solutions":["Point -Dgraal.OptimizationLogPath at an existing, writable directory (verify with touch)","Free disk space or raise the container's storage/ephemeral limit","In containers/sandboxes, mount a writable volume for dump and log output and pass that path","If the log is not needed, disable the OptimizationLog option to remove the write entirely"],"exampleFix":"# before\nnative-image -H:OptimizationLog=... -H:OptimizationLogPath=/opt/app/logs ... # /opt read-only\n\n# after\nmkdir -p /tmp/optlog && chmod u+w /tmp/optlog\nnative-image -H:OptimizationLog=... -H:OptimizationLogPath=/tmp/optlog ...","handlingStrategy":"try-catch","validationCode":"Path dir = Path.of(options.get(\"graal.OptimizationLogPath\"));\nFiles.createDirectories(dir);\nif (!Files.isWritable(dir)) throw new IllegalStateException(\"OptimizationLogPath not writable: \" + dir);","typeGuard":null,"tryCatchPattern":"// The error is thrown by the compiler itself; guard around launching the build:\nif (!Files.isWritable(logDir)) { disableOptimizationLog(); } // or fail fast with a clear message","preventionTips":["Verify the log directory is writable before builds (esp. in containers)","Use absolute paths for dump/log options to avoid cwd surprises","Monitor disk space on CI agents that accumulate optimization logs"],"tags":["graalvm","optimization-log","io","filesystem","configuration"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}