{"record":{"id":"eca0f583d58464e2","repo":"HMCL-dev/HMCL","slug":"illegal-result","errorCode":null,"errorMessage":"Illegal result: ","messagePattern":"Illegal result: ","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"HMCL/src/main/java/org/jackhuang/hmcl/ui/main/JavaDownloadDialog.java","lineNumber":380,"sourceCode":"            }\n        }\n\n        private void onDownload() {\n            fireEvent(new DialogCloseEvent());\n\n            DiscoJavaDistribution distribution = distributionBox.getSelectionModel().getSelectedItem();\n            DiscoJavaRemoteVersion version = remoteVersionBox.getSelectionModel().getSelectedItem();\n            JavaPackageType packageType = packageTypeBox.getSelectionModel().getSelectedItem();\n\n            if (version == null)\n                return;\n\n            Controllers.taskDialog(new GetTask(downloadProvider.injectURLWithCandidates(version.getLinks().pkgInfoUri()))\n                    .setExecutor(Schedulers.io())\n                    .thenComposeAsync(json -> {\n                        DiscoResult<DiscoRemoteFileInfo> result = JsonUtils.fromNonNullJson(json, DiscoResult.typeOf(DiscoRemoteFileInfo.class));\n                        if (result.getResult().size() != 1)\n                            throw new IOException(\"Illegal result: \" + json);\n\n                        DiscoRemoteFileInfo fileInfo = result.getResult().get(0);\n                        if (StringUtils.isNotBlank(fileInfo.checksumType())\n                                && !fileInfo.checksumType().equals(\"sha1\") && !fileInfo.checksumType().equals(\"sha256\") && !fileInfo.checksumType().equals(\"md5\"))\n                            throw new IOException(\"Unsupported checksum type: \" + fileInfo.checksumType());\n                        if (StringUtils.isBlank(fileInfo.directDownloadUri()))\n                            throw new IOException(\"Missing download URI: \" + json);\n\n                        Path targetFile = Files.createTempFile(\"hmcl-java-\", \".\" + version.getArchiveType());\n                        targetFile.toFile().deleteOnExit();\n\n                        Task<FileDownloadTask.IntegrityCheck> getIntegrityCheck;\n                        if (StringUtils.isNotBlank(fileInfo.checksum()))\n                            getIntegrityCheck = Task.completed(new FileDownloadTask.IntegrityCheck(fileInfo.checksumType(), fileInfo.checksum()));\n                        else if (StringUtils.isNotBlank(fileInfo.checksumUri()))\n                            getIntegrityCheck = new GetTask(downloadProvider.injectURLWithCandidates(fileInfo.checksumUri()))\n                                    .thenApplyAsync(checksum -> {\n                                        checksum = checksum.trim();","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/JavaDownloadDialog.java#L362-L398","documentation":"In JavaDownloadDialog's Disco (foojay) download flow, the pkgInfoUri metadata is fetched and parsed into a DiscoResult, and the code requires exactly one result entry. If the Disco API returns zero or multiple matching packages, the dialog throws IOException(\"Illegal result: \" + json). It guards against ambiguous or empty upstream download resolution.","triggerScenarios":"Clicking download in the Java download dialog when the foojay Disco API's package-info endpoint returns a result array whose size != 1 (0 matches for the requested distro/version/ architecture, or 2+ ambiguous matches).","commonSituations":"Requesting an unusual Java version/arch/libc combination the Disco API maps to multiple or zero artifacts; upstream API schema or data changes; stale version metadata links from the version manifest.","solutions":["Pick a different (more common) Java distribution/version or architecture in the dialog and retry","Check the Disco API response (the JSON is appended to the message) to see what was actually returned","Manually download the JDK from the vendor and add it via the Java management page","Update HMCL so its Disco endpoint/parameters match current upstream API behavior"],"exampleFix":"// before\nif (result.getResult().size() != 1)\n    throw new IOException(\"Illegal result: \" + json);\n// after\nif (result.getResult().isEmpty())\n    throw new IOException(\"No matching package found: \" + json);\nif (result.getResult().size() > 1)\n    LOG.warning(\"Multiple Disco results, using the first of \" + result.getResult().size());","handlingStrategy":"try-catch","validationCode":"// query the Disco API before offering the download\nHttpResponse<String> resp = client.send(pkgInfoRequest, ofString());\nJsonArray results = JsonParser.parseString(resp.body())\n    .getAsJsonObject().getAsJsonArray(\"result\");\nif (results == null || results.size() != 1)\n    throw new IllegalStateException(\"Disco returned \" + (results == null ? 0 : results.size()) + \" candidates\");","typeGuard":null,"tryCatchPattern":"try {\n    downloadJava(version);\n} catch (IOException e) {\n    if (e.getMessage().startsWith(\"Illegal result:\")) {\n        Controllers.dialog(\"No unique Java package found for this version/architecture; choose another distribution\");\n    } else throw e;\n}","preventionTips":["Prefer common distribution/version/architecture combinations that map to exactly one Disco result","Keep HMCL updated for current foojay API parameter semantics","Have a fallback path: manual JDK download + add via Java management"],"tags":["network","api","java-download","json"],"backgroundTag":"unexpected-api-response-shape","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"}