java io_error ai_generated true

java.util.zip.ZipException: invalid LOC header (bad signature)

ID: java/zip-malformed

Also available as: JSON · Markdown
83%Fix Rate
86%Confidence
65Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
21 active

Root Cause

Java's ZIP/JAR file reader encountered a corrupted or invalid archive. The most common causes are: corrupted JAR files in the Maven/Gradle cache (partially downloaded), ZIP files created with incompatible tools or formats (ZIP64 issues), files that are not actually ZIP archives despite having a .zip or .jar extension, or truncated downloads. This error frequently manifests during build tool dependency resolution or when loading libraries at runtime.

generic

Workarounds

  1. 90% success Delete the corrupted artifact from the local cache and rebuild
    For Maven: delete the specific artifact directory under ~/.m2/repository/ (e.g., rm -rf ~/.m2/repository/com/example/artifact/1.0/) and run mvn clean install. For Gradle: delete from ~/.gradle/caches/ and run gradle clean build --refresh-dependencies. To nuke the entire cache: rm -rf ~/.m2/repository (Maven) or rm -rf ~/.gradle/caches (Gradle). Check that the re-downloaded file is complete (compare size with the remote repository).
  2. 85% success Verify the file is a valid ZIP archive and check for download/transfer corruption
    Test the file: unzip -t suspect.jar. Check the file type: file suspect.jar (should show 'Java archive data' or 'Zip archive data'). If the file is actually HTML (e.g., a 302 redirect page), the repository URL or authentication is wrong. For corporate proxies/Nexus, ensure credentials are correct in settings.xml. For large JARs, verify no network interruption during download by comparing file sizes.

Dead Ends

Common approaches that don't work:

  1. Retrying the build without clearing the dependency cache 90% fail

    If the ZIP/JAR file in the cache is corrupted, retrying the build will use the same corrupted cached file. Maven and Gradle do not verify the integrity of cached artifacts on subsequent builds. The corrupted file must be deleted first.

  2. Attempting to repair the ZIP file programmatically with ZipInputStream 80% fail

    ZipInputStream can sometimes read partial entries from a damaged ZIP, but it cannot reconstruct missing or corrupted data. The local file headers (LOC) and central directory (CEN) must be intact for reliable extraction. A truly corrupted archive needs to be re-downloaded, not repaired.

Error Chain

Leads to:
Preceded by:
Frequently confused with: