JDK-8182377 : Unspecific NPE for strange but seemingly valid empty zip file
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.jar
  • Affected Version: 8
  • Priority: P4
  • Status: Resolved
  • Resolution: Won't Fix
  • OS: generic
  • CPU: generic
  • Submitted: 2017-06-13
  • Updated: 2017-11-28
  • Resolved: 2017-11-28
Description
FULL PRODUCT VERSION :


A DESCRIPTION OF THE PROBLEM :
java.util.zip.ZipFile throws an NPE when processing the following jar file:

http://repo1.maven.org/maven2/org/seleniumhq/selenium/selenium-java/3.4.0/selenium-java-3.4.0-javadoc.jar

Using the Linux tool "unzip" shows the following:

$ unzip -v selenium-java-3.4.0-javadoc.jar
Archive:  selenium-java-3.4.0-javadoc.jar
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
       0  Stored        0   0% 02-01-1985 00:00 00000000
--------          -------  ---                            -------
       0                0   0%                            1 file

java.util.zip.ZipFile shows:

$ jar tf selenium-java-3.4.0-javadoc.jar
java.lang.NullPointerException
        at java.util.zip.ZipFile.getZipEntry(ZipFile.java:566)
        at java.util.zip.ZipFile.access$900(ZipFile.java:60)
        at java.util.zip.ZipFile$ZipEntryIterator.next(ZipFile.java:524)
        at java.util.zip.ZipFile$ZipEntryIterator.nextElement(ZipFile.java:499)
        at java.util.zip.ZipFile$ZipEntryIterator.nextElement(ZipFile.java:480)
        at sun.tools.jar.Main.list(Main.java:1118)
        at sun.tools.jar.Main.run(Main.java:293)
        at sun.tools.jar.Main.main(Main.java:1288)

If this is a badly formatted jar file, I'd at least expect the ZipFile class to throw a checked Exception, ie. IOException or something that relates to bad jar file format.

Because of the unspecific NPE Eclipse is currently throwing unhandled errors.


REPRODUCIBILITY :
This bug can be reproduced always.


Comments
To reproduce the issue, try to extract the jar using jar tvf ./selenium-java-3.4.0-javadoc.jar Following are the results: JDK 8 - fail JDK 8u131 - Fail JDK 9-ea+170 - Pass Following is output on JDK 8u131: java.lang.NullPointerException at java.util.zip.ZipFile.getZipEntry(ZipFile.java:567) at java.util.zip.ZipFile.access$900(ZipFile.java:61) at java.util.zip.ZipFile$ZipEntryIterator.next(ZipFile.java:525) at java.util.zip.ZipFile$ZipEntryIterator.nextElement(ZipFile.java:500) at java.util.zip.ZipFile$ZipEntryIterator.nextElement(ZipFile.java:481) at sun.tools.jar.Main.list(Main.java:1063) at sun.tools.jar.Main.run(Main.java:291) at sun.tools.jar.Main.main(Main.java:1233) Following is the output on setting verbose option on JDK 9-ea+174: D:\>jar tvf selenium-java-3.4.0-javadoc.jar 0 Fri Feb 01 00:00:00 IST 1985
27-06-2017