{"record":{"id":"19e448fd88f71ebf","repo":"HMCL-dev/HMCL","slug":"platform-is-mismatch-expected","errorCode":null,"errorMessage":"Platform is mismatch: expected ","messagePattern":"Platform is mismatch: expected ","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"HMCL/src/main/java/org/jackhuang/hmcl/java/HMCLJavaRepository.java","lineNumber":194,"sourceCode":"                    }\n                } else if (file instanceof MojangJavaRemoteFiles.RemoteDirectory) {\n                    files.put(path, new JavaLocalFiles.LocalDirectory());\n                } else if (file instanceof MojangJavaRemoteFiles.RemoteLink) {\n                    files.put(path, new JavaLocalFiles.LocalLink(((MojangJavaRemoteFiles.RemoteLink) file).getTarget()));\n                }\n            });\n\n            JavaManifest manifest = new JavaManifest(info, update, files);\n            JsonUtils.writeToJsonFile(getManifestFile(platform, gameJavaVersion), manifest);\n            return JavaRuntime.of(executable, info, true);\n        });\n    }\n\n    public Task<JavaRuntime> getInstallJavaTask(Platform platform, String name, Map<String, Object> update, Path archiveFile) {\n        Path javaDir = getJavaDir(platform, name);\n        return new JavaInstallTask(javaDir, update, archiveFile).thenApplyAsync(result -> {\n            if (!result.info().getPlatform().equals(platform))\n                throw new IOException(\"Platform is mismatch: expected \" + platform + \" but got \" + result.info().getPlatform());\n\n            Path executable = javaDir.resolve(\"bin\").resolve(platform.getOperatingSystem().getJavaExecutable()).toRealPath();\n            JsonUtils.writeToJsonFile(getManifestFile(platform, name), result);\n            return JavaRuntime.of(executable, result.info(), true);\n        });\n    }\n\n    @Override\n    public Task<Void> getUninstallJavaTask(Platform platform, String name) {\n        return Task.runAsync(() -> {\n            Files.deleteIfExists(getManifestFile(platform, name));\n            FileUtils.deleteDirectory(getJavaDir(platform, name));\n        });\n    }\n\n    @Override\n    public Task<Void> getUninstallJavaTask(JavaRuntime java) {\n        return Task.runAsync(() -> {","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCL/src/main/java/org/jackhuang/hmcl/java/HMCLJavaRepository.java#L176-L212","documentation":"getInstallJavaTask validates that the Java runtime produced by JavaInstallTask reports the same platform that was requested. If the unpacked JDK's info().getPlatform() differs from the requested Platform (e.g. wrong architecture or OS), an IOException is thrown and the installation is rejected.","triggerScenarios":"Calling getInstallJavaTask(platform, name, update, archiveFile) where the downloaded/extracted JDK binary is built for a different OS or CPU architecture than the requested platform — e.g. requesting windows-x86_64 but the archive contains an ARM64 JDK, or downloading on a mismatched mirror.","commonSituations":"Wrong architecture JDK chosen (x86 vs arm64 vs x86_64); misconfigured download source serving the wrong platform; corrupted or mislabeled JDK archive; user manually placed a wrong-arch archive.","solutions":["Re-run the installation so HMCL re-resolves the correct JDK for the requested platform","Verify the JDK archive's architecture/OS matches the target platform before installing","Check the Mojang/adoptium mirror serving the archive is returning the right build","If the platform string is wrong, pass the correct Platform to getInstallJavaTask"],"exampleFix":"// before\ntask = repo.getInstallJavaTask(Platform.WINDOWS_X86_64, name, update, archive);\n// after\ntask = repo.getInstallJavaTask(Platform.SYSTEM_PLATFORM, name, update, archive); // let HMCL pick matching platform\n","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    Task<JavaRuntime> task = repo.getInstallJavaTask(platform, name, update, archiveFile);\n} catch (IOException e) {\n    if (e.getMessage().startsWith(\"Platform is mismatch\")) {\n        ui.reportWrongArchitectureDownload();\n    } else {\n        throw e;\n    }\n}","preventionTips":["Always use Platform.SYSTEM_PLATFORM (or equivalent) instead of hardcoding a platform","Verify the JDK download source returns builds matching the requested platform","Delete partial/corrupted JDK archives before retrying installation"],"tags":["java","platform-mismatch","architecture","jdk-install"],"backgroundTag":"unsupported-platform","analyzedSha":"24702dc5a0214034f4c27166d5fd30cad08cec19","analyzedAt":"2026-09-10T12:36:46.680Z","contentChangedAt":"2026-09-10T12:36:46.680Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}