{"record":{"id":"95e39718bf523f33","repo":"HMCL-dev/HMCL","slug":"not-a-zip-file","errorCode":null,"errorMessage":"Not a zip file","messagePattern":"Not a zip file","errorType":"exception","errorClass":"ZipException","httpStatus":null,"severity":"error","filePath":"HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/CompressingUtils.java","lineNumber":242,"sourceCode":"    public static FileSystem createWritableZipFileSystem(Path zipFile, Charset charset) throws IOException {\n        return createZipFileSystem(zipFile, true, true, charset);\n    }\n\n    public static FileSystem createZipFileSystem(Path zipFile, boolean create, boolean useTempFile, Charset encoding) throws IOException {\n        Map<String, Object> env = new HashMap<>();\n        if (create)\n            env.put(\"create\", \"true\");\n        if (encoding != null)\n            env.put(\"encoding\", encoding.name());\n        if (useTempFile)\n            env.put(\"useTempFile\", true);\n        try {\n            if (ZIPFS_PROVIDER == null)\n                throw new FileSystemNotFoundException(\"Module jdk.zipfs does not exist\");\n\n            return ZIPFS_PROVIDER.newFileSystem(zipFile, env);\n        } catch (UnsupportedOperationException ex) {\n            throw new ZipException(\"Not a zip file\");\n        } catch (FileSystemNotFoundException ex) {\n            throw Lang.apply(new ZipException(\"Java Environment is broken\"), it -> it.initCause(ex));\n        }\n    }\n\n    /**\n     * Read the text content of a file in zip.\n     *\n     * @param zipFile the zip file\n     * @param name    the location of the text in zip file, something like A/B/C/D.txt\n     * @return the plain text content of given file.\n     * @throws IOException if the file is not a valid zip file.\n     */\n    public static String readTextZipEntry(Path zipFile, String name) throws IOException {\n        try (ZipArchiveReader s = new ZipArchiveReader(zipFile)) {\n            return readTextZipEntry(s, name);\n        }\n    }","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/CompressingUtils.java#L224-L260","documentation":"When the jdk.zipfs provider exists but the file cannot be mounted as a zip filesystem, the underlying provider signals UnsupportedOperationException, which createZipFileSystem translates into a ZipException with the message 'Not a zip file'. This is the API-level signal that the target file is not a valid zip archive.","triggerScenarios":"Calling createZipFileSystem (via createReadOnlyZipFileSystem or createWritableZipFileSystem) on a path that is not a zip archive — wrong file, corrupted data, or a different compression format (e.g. gzip, tar) renamed to .zip.","commonSituations":"Pointing mod/installer code at a partially downloaded or HTML error page saved as .zip; archives created by non-zip tools; truncated downloads.","solutions":["Verify the file is a real zip: check the PK magic bytes or open it with java.util.zip.ZipFile first.","Re-download or re-extract the archive; validate its checksum against the source.","Catch ZipException around createReadOnlyZipFileSystem/createWritableZipFileSystem and report the file as corrupt/unsupported to the user."],"exampleFix":"// before\nFileSystem fs = CompressingUtils.createReadOnlyZipFileSystem(path); // ZipException on junk\n\n// after\ntry (ZipFile zf = new ZipFile(path.toFile())) {\n    FileSystem fs = CompressingUtils.createReadOnlyZipFileSystem(path);\n} catch (ZipException e) {\n    throw new IOException(\"Invalid or corrupted zip: \" + path, e);\n}","handlingStrategy":"validation","validationCode":"static void requireZip(Path p) throws IOException {\n    try (DataInputStream in = new DataInputStream(Files.newInputStream(p))) {\n        if (in.readInt() != 0x504B0304) throw new IOException(\"Not a zip file: \" + p);\n    }\n}","typeGuard":null,"tryCatchPattern":"try { return CompressingUtils.createReadOnlyZipFileSystem(path); } catch (ZipException e) { log.warn(\"Not a zip file: \" + path, e); throw new InvalidArchiveException(path, e); }","preventionTips":["Validate zip magic bytes before mounting zip filesystems.","Verify download integrity (size/checksum) before use.","Do not trust file extensions; treat .zip as untrusted input."],"tags":["zip","file-format","validation","io"],"backgroundTag":"file-read-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"}