java.util.zip.ZipError: invalid CEN header (bad signature)
Asked Answered
H

7

16

I'm using Java 1.7.0_40 on Red Hat Linux and I have the following code:

Path zipfile = Paths.get(filename);
FileSystem fs = FileSystems.newFileSystem(zipfile, FileTest.class.getClassLoader());

The filename variable points to a zip file that is 788MB. The uncompressed size of the zip file is 8.3GB. When I run the code above I get the following exception:

Exception in thread "main" java.util.zip.ZipError: invalid CEN header (bad signature)
        at com.sun.nio.zipfs.ZipFileSystem.zerror(ZipFileSystem.java:1605)
        at com.sun.nio.zipfs.ZipFileSystem.initCEN(ZipFileSystem.java:1058)
        at com.sun.nio.zipfs.ZipFileSystem.<init>(ZipFileSystem.java:130)
        at com.sun.nio.zipfs.ZipFileSystemProvider.newFileSystem(ZipFileSystemProvider.java:139)
        at java.nio.file.FileSystems.newFileSystem(FileSystems.java:386)
        at FileTest.readFromZip(FileTest.java:35)
        at FileTest.main(FileTest.java:25)

I was under the impression that Java 7 was capable of handling large zip files. Can anyone explain why this is happening?

Thanks.

Heartwarming answered 20/3, 2014 at 14:38 Comment(1)
Possible duplicate of Compile error in maven2: "invalid CEN header (bad signature)"Dinky
O
17

I too faced the issue in Maven based project. The issue occurred because of corrupted jars. Deleted the jars from .m2 folder and built the project again; and it worked like charm.

Ostrander answered 12/11, 2014 at 9:38 Comment(0)
L
12

This problem occurs Due to jar file was downloaded is corrupted.

if you are using Maven.

  • For Solving this issue, Delete Particular Jar File in C:/Users/public/.m2/repository folder.
  • After that add New Version of Maven in POM.xml.
  • Rebuild and try. It will work fine.
Larkin answered 17/10, 2015 at 13:22 Comment(0)
H
6

There are two possible explanations:

Heindrick answered 20/3, 2014 at 23:7 Comment(0)
P
1

In my case i solved it by changing Zip64Mode.Always by Zip64Mode.AsNeeded in the step when i create the zip file, so this looks like this:

ZipArchiveOutputStream zaos = new ZipArchiveOutputStream(os);
        zaos.setCreateUnicodeExtraFields(UnicodeExtraFieldPolicy.ALWAYS);
        zaos.setUseLanguageEncodingFlag(true);
        zaos.setUseZip64(Zip64Mode.AsNeeded);
        zaos.setFallbackToUTF8(true);
        zaos.setEncoding("UTF-8");

Then this line of code starts to work:

try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) {
.
.
.
}

By the way, using Java 8.

Piker answered 1/10, 2021 at 15:26 Comment(0)
O
0

Large file (4GB+) support for zip archives (i.e. 64-bit zip support) was addressed by issue JDK-4681995 ("Add support for large (> 4GB) zip/jar files").

However, this change was not included in Java 7 until 1.7.0 build 55, which was a few builds after the specific version (1.7.0 build 40) that you were using. Updating to build 55 or later would solve the problem.

Ofeliaofella answered 8/7, 2019 at 14:49 Comment(0)
S
0

If you have arrived at this post due to a compilation problem in your Jenkins.

Know that most likely you are running Jenkins with a more updated JDK and your project is compatible with an older version of Java, making it necessary for you to install another version of the JDK in parallel on your VM/Container.

In Jenkins, the option is called “With Ant” and allows you to select Java with the specific version to build your project.

Stinko answered 8/7 at 13:29 Comment(0)
K
-1

It is problem of configuration for maven compiler in your pom file. Default version java source and target is 1.5, even used JDK has higher version.

To fix, add maven compiler plugin configuration section with higher java version, example:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.6.1</version>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
  </configuration>
</plugin>

For more info check these links:

maven compiler

bug report

Kumkumagai answered 25/3, 2017 at 10:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.