{"record":{"id":"f0bad09cd442ca5a","repo":"HMCL-dev/HMCL","slug":"remote-response-metadata-is-unavailable","errorCode":null,"errorMessage":"Remote response metadata is unavailable","messagePattern":"Remote response metadata is unavailable","errorType":"exception","errorClass":"java.io.IOException","httpStatus":null,"severity":"error","filePath":"HMCLCore/src/main/java/org/jackhuang/hmcl/task/CacheFileTask.java","lineNumber":141,"sourceCode":"        return EnumCheckETag.CHECK_E_TAG;\n    }\n\n    @Override\n    protected void useCachedResult(Path cache) {\n        setResult(cache);\n    }\n\n    /// Creates a temporary sink that publishes a successful download to the cache repository.\n    ///\n    /// @param response     the HTTP response metadata\n    /// @param checkETag    whether remote cache metadata is being checked\n    /// @param bmclapiHash  the hash supplied by BMCLAPI, or `null`\n    /// @return the temporary download sink\n    /// @throws IOException if the temporary file cannot be created\n    @Override\n    protected Context getContext(@Nullable UrlResponseInfo response, boolean checkETag, @Nullable String bmclapiHash) throws IOException {\n        if (expectedSha1 == null && (!checkETag || response == null)) {\n            throw new IOException(\"Remote response metadata is unavailable\");\n        }\n\n        return new Context() {\n            private final Path temp = Files.createTempFile(\"hmcl-download-\", null);\n            private final FileChannel fileOutput = FileChannel.open(temp,\n                    StandardOpenOption.WRITE,\n                    StandardOpenOption.TRUNCATE_EXISTING,\n                    StandardOpenOption.CREATE);\n\n            @Override\n            public void reset() throws IOException {\n                fileOutput.truncate(0L);\n            }\n\n            @Override\n            public void write(byte[] buffer, int offset, int len) throws IOException {\n                ByteBuffer byteBuffer = ByteBuffer.wrap(buffer, offset, len);\n                while (byteBuffer.hasRemaining()) {","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCLCore/src/main/java/org/jackhuang/hmcl/task/CacheFileTask.java#L123-L159","documentation":"CacheFileTask.getContext() needs some way to verify the downloaded content: either a pre-configured expected SHA-1 or the remote response's metadata (ETag). This IOException is thrown when expectedSha1 is null AND (the caller asked for ETag checking while the response info is null), meaning no integrity reference is available.","triggerScenarios":"Running a CacheFileTask without calling setExpectedSha1(), while the underlying network layer returns a null UrlResponseInfo (e.g. non-HTTP download path or missing response) with checkETag=true, or checkETag=false with no expectedSha1.","commonSituations":"Configuring a cached download without a checksum against a source that does not supply response metadata; network layer short-circuits and returns null response info; refactors that drop the expectedSha1 configuration.","solutions":["Call setExpectedSha1(...) on the task with the known SHA-1 of the artifact before executing","Ensure the download URL is an HTTP(S) source that returns response headers so UrlResponseInfo is populated","Check that the network client is not returning null response info for your transport (e.g. non-HTTP protocols)","If no verification is possible, do not use the cache-verified variant of the task"],"exampleFix":"// before\nCacheFileTask task = new CacheFileTask(url, file, null);\n// after\ntask.setExpectedSha1(knownSha1);\nCacheFileTask task = new CacheFileTask(url, file, knownSha1);","handlingStrategy":"try-catch","validationCode":"if (expectedSha1 == null) {\n    // ensure a checksum is configured before running the task\n    task.setExpectedSha1(computeOrFetchKnownSha1(artifact));\n}","typeGuard":null,"tryCatchPattern":"try {\n    cacheFileTask.run();\n} catch (IOException e) {\n    if (e.getMessage().contains(\"Remote response metadata is unavailable\"))\n        configureSha1AndRetry();\n    else throw e;\n}","preventionTips":["Always set expectedSha1 when the source may not return headers","Prefer HTTPS endpoints that expose ETag/Content-Length","Unit-test task configuration to fail fast on missing checksums"],"tags":["download","integrity","sha1","http"],"backgroundTag":"missing-required-argument","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"}