JDK-6190121 : Jar is not usable for testing integrity of Jar files.
  • Type: Enhancement
  • Component: tools
  • Sub-Component: jar
  • Affected Version: 1.4.2_05,6
  • Priority: P4
  • Status: Resolved
  • Resolution: Won't Fix
  • OS: generic,solaris_8
  • CPU: generic
  • Submitted: 2004-11-03
  • Updated: 2022-03-02
  • Resolved: 2022-03-02
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
We have a known corrupt jar file called saxorig.jar, but:

jar tvf saxorig.jar 

...works fine.

A test program which opens the problem file as either JarFile or a ZipFile will fail:

(5.9)$ java ListJar saxorig.jar
Error accessing: saxorig.jar: java.util.zip.ZipException: error in opening zip file
java.util.zip.ZipException: error in opening zip file
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:112)
        at java.util.jar.JarFile.<init>(JarFile.java:127)
        at java.util.jar.JarFile.<init>(JarFile.java:65)
        at ListJar.main(ListJar.java:11)
        
"jar tvf" would seem like a reasonable test for corrupt Jar/Zip files, but (some) corrupt files can pass that test, yet still be unusable.  "jar xvf" can even extract all the files in the case of this specific instance of a captured corrupt jar file, while the classloader and the attached test program fail to open it.
(Yes, extracting and repackaging the jar fixes the problem.)
###@###.### 11/3/04 15:44 GMT

Comments
EVALUATION Some of the data in a jar file is redundant, so if one copy is corrupt, everything might still work because Java is looking at the other copy. Testing all the data for integrity may be prohibitively slow in some cases. We should have a way of testing jar files for all sorts of internal integrity errors. ###@###.### 2005-04-19 03:07:48 GMT
03-11-2004