I am extracting a ZIP file in java:
ZipFile zipFile = new ZipFile(theZipFile);
Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
while(zipEntries.hasMoreElements()){
ZipEntry entry = zipEntries.nextElement(); /// <---Nullpointer exception happens here
}
The code execution past while(zipEntries.hasMoreElements()) but failed at extracting a ZipEntry.
It’s strange that hasMoreElements returns true, but null pointer occurs when trying to get elements out.
The exception is from within the ZipFile class from JDK lib, which I can not see local variables in debugger, so how do I find out what is wrong with the Zip file?
Edit:
Stack trace:
java.lang.NullPointerException
at java.util.zip.ZipFile.getZipEntry(ZipFile.java:529)
at java.util.zip.ZipFile.access$900(ZipFile.java:56)
at java.util.zip.ZipFile$1.nextElement(ZipFile.java:511)
at java.util.zip.ZipFile$1.nextElement(ZipFile.java:481)
Here is the
getZipEntrymethod (as of 1.7.0_10):The only reason a
NullPointerExceptionwould be thrown on this line would be ife,zc, orbnamewerenull.ecannot benullbecause it is clearly instantiated in this method.zccannot benull:Which means that
bnamemust benull, which is going to be pretty hard to debug.getEntryBytesis anativemethod:This is how I would proceed:
getEntryBytesthat was fixed