java io_error ai_generated true

java.util.zip.ZipException: error in opening zip file

ID: java/zip-file-open-error

Also available as: JSON · Markdown · 中文
82%Fix Rate
88%Confidence
1Evidence
2023-01-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Java 8 active
Java 11 active
Java 17 active
Java 21 active

Root Cause

The JVM or application attempted to open a ZIP or JAR file that is corrupted, truncated, or not a valid ZIP format, often due to incomplete downloads, disk errors, or file system corruption.

generic

中文

JVM或应用程序尝试打开一个损坏、截断或不是有效ZIP格式的ZIP或JAR文件,通常是由于下载不完整、磁盘错误或文件系统损坏。

Official Documentation

https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/zip/ZipException.html

Workarounds

  1. 90% success Verify the ZIP file integrity using `unzip -t <file.zip>` (Linux/macOS) or `jar -tf <file.jar>` (Java). If it reports errors, obtain a fresh copy from the original source and compare checksums: `sha256sum <file.zip>`.
    Verify the ZIP file integrity using `unzip -t <file.zip>` (Linux/macOS) or `jar -tf <file.jar>` (Java). If it reports errors, obtain a fresh copy from the original source and compare checksums: `sha256sum <file.zip>`.
  2. 85% success If the file is a Maven/Gradle dependency, clear the local repository cache: `rm -rf ~/.m2/repository/<group>/<artifact>` (Maven) or `rm -rf ~/.gradle/caches/` (Gradle), then rebuild the project to force re-download.
    If the file is a Maven/Gradle dependency, clear the local repository cache: `rm -rf ~/.m2/repository/<group>/<artifact>` (Maven) or `rm -rf ~/.gradle/caches/` (Gradle), then rebuild the project to force re-download.
  3. 75% success For JAR files in the classpath, check file permissions: `ls -l <file.jar>` and ensure the application user has read access. Use `chmod +r <file.jar>` to fix permissions if needed.
    For JAR files in the classpath, check file permissions: `ls -l <file.jar>` and ensure the application user has read access. Use `chmod +r <file.jar>` to fix permissions if needed.

中文步骤

  1. Verify the ZIP file integrity using `unzip -t <file.zip>` (Linux/macOS) or `jar -tf <file.jar>` (Java). If it reports errors, obtain a fresh copy from the original source and compare checksums: `sha256sum <file.zip>`.
  2. If the file is a Maven/Gradle dependency, clear the local repository cache: `rm -rf ~/.m2/repository/<group>/<artifact>` (Maven) or `rm -rf ~/.gradle/caches/` (Gradle), then rebuild the project to force re-download.
  3. For JAR files in the classpath, check file permissions: `ls -l <file.jar>` and ensure the application user has read access. Use `chmod +r <file.jar>` to fix permissions if needed.

Dead Ends

Common approaches that don't work:

  1. Re-download the ZIP file using the same URL without verifying integrity 70% fail

    If the source server or network path is unreliable, re-downloading the same file may still result in a corrupted copy. Without checksum validation (e.g., MD5 or SHA-256), the corruption persists.

  2. Increase JVM memory with -Xmx 95% fail

    Memory settings do not affect the ability to open a corrupted ZIP file. The error is a file integrity issue, not a memory allocation problem.