{"record":{"id":"0f4d321797c29c7c","repo":"HMCL-dev/HMCL","slug":"optifine-patcher-failed-command-command","errorCode":null,"errorMessage":"OptiFine patcher failed, command: ${command}","messagePattern":"OptiFine patcher failed, command: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFineInstallTask.java","lineNumber":187,"sourceCode":"        }\n\n        // Install launch wrapper modified by OptiFine\n        boolean hasLaunchWrapper = false;\n        try (FileSystem fs = CompressingUtils.createReadOnlyZipFileSystem(installerFile)) {\n            Path optiFineLibraryPath = gameRepository.getLayout().getLibraryFile(manifest.id(), optiFineLibrary);\n            if (Files.exists(fs.getPath(\"optifine/Patcher.class\"))) {\n                String[] command = {\n                        JavaRuntime.getDefault().getBinary().toString(),\n                        \"-cp\",\n                        installerFile.toString(),\n                        \"optifine.Patcher\",\n                        minecraftJar.toAbsolutePath().normalize().toString(),\n                        installerFile.toString(),\n                        optiFineLibraryPath.toString()\n                };\n                int exitCode = SystemUtils.callExternalProcess(command);\n                if (exitCode != 0)\n                    throw new IOException(\"OptiFine patcher failed, command: \" + new CommandBuilder().addAll(Arrays.asList(command)));\n            } else {\n                FileUtils.copyFile(installerFile, optiFineLibraryPath);\n            }\n\n            try (FileSystem fs2 = CompressingUtils.createWritableZipFileSystem(optiFineLibraryPath)) {\n                Files.deleteIfExists(fs2.getPath(\"/META-INF/mods.toml\"));\n            }\n\n            Path launchWrapper2 = fs.getPath(\"launchwrapper-2.0.jar\");\n            if (Files.exists(launchWrapper2)) {\n                Library launchWrapper = new Library(new Artifact(\"optifine\", \"launchwrapper\", \"2.0\"));\n                Path launchWrapperFile = gameRepository.getLayout().getLibraryFile(manifest.id(), launchWrapper);\n                Files.createDirectories(launchWrapperFile.toAbsolutePath().getParent());\n                FileUtils.copyFile(launchWrapper2, launchWrapperFile);\n                hasLaunchWrapper = true;\n                libraries.add(launchWrapper);\n            }\n","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFineInstallTask.java#L169-L205","documentation":"Thrown when the external OptiFine patcher process (java -jar invoking the OptiFine installer against the client jar) exits with a non-zero code. The IOException includes the full command line so the failing invocation can be reproduced.","triggerScenarios":"SystemUtils.callExternalProcess(command) returns non-zero while running the OptiFine patch command with [minecraftJar, installerFile, optiFineLibraryPath] — e.g. wrong Java version, incompatible OptiFine/game version combo, corrupted client jar, or file locks.","commonSituations":"Running the patcher with a too-new/too-old JRE, OptiFine build not matching the Minecraft version, corrupted downloads, or paths with spaces/odd characters breaking the external process.","solutions":["Re-run with a Java version compatible with the OptiFine installer (usually Java 8+; match the game's requirement).","Re-download both the client jar and OptiFine installer to rule out corruption.","Run the exact command printed in the exception manually to see the patcher's own error output.","Check target paths are writable and not locked by another process."],"exampleFix":"// before\nint exitCode = SystemUtils.callExternalProcess(command);\nif (exitCode != 0)\n    throw new IOException(\"OptiFine patcher failed, command: \" + new CommandBuilder().addAll(Arrays.asList(command)));\n// after\nint exitCode = SystemUtils.callExternalProcess(command);\nif (exitCode != 0)\n    throw new IOException(\"OptiFine patcher failed (exit \" + exitCode + \"), command: \"\n        + new CommandBuilder().addAll(Arrays.asList(command)));","handlingStrategy":"try-catch","validationCode":"Path javaBin = resolveGameJava(manifest); // ensure Java version matches OptiFine requirement\nif (!Files.isRegularFile(minecraftJar) || !Files.isRegularFile(installerFile))\n    throw new IllegalStateException(\"inputs missing\");","typeGuard":null,"tryCatchPattern":"try {\n    await(task);\n} catch (IOException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"OptiFine patcher failed\")) {\n        // run the embedded command manually to see the patcher's stderr\n        log.severe(e.getMessage());\n    }\n}","preventionTips":["Match the JVM version to what the OptiFine installer supports","Re-download corrupted client jars/installers","Avoid paths with problematic characters for external processes","Check the patcher's own output by reproducing the command"],"tags":["optifine","external-process","patcher","java-version","exit-code"],"backgroundTag":"http-request-failed","analyzedSha":"24702dc5a0214034f4c27166d5fd30cad08cec19","analyzedAt":"2026-09-10T12:36:46.680Z","contentChangedAt":"2026-09-10T12:36:46.680Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}