Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9318479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:08:19+00:00 2026-06-19T03:08:19+00:00

I am extracting a ZIP file in java: ZipFile zipFile = new ZipFile(theZipFile); Enumeration<?

  • 0

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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T03:08:20+00:00Added an answer on June 19, 2026 at 3:08 am

    Here is the getZipEntry method (as of 1.7.0_10):

    private ZipEntry getZipEntry(String name, long jzentry) {
        ZipEntry e = new ZipEntry();
        e.flag = getEntryFlag(jzentry);  // get the flag first
        if (name != null) {
            e.name = name;
        } else {
            byte[] bname = getEntryBytes(jzentry, JZENTRY_NAME);
            if (!zc.isUTF8() && (e.flag & EFS) != 0) {
                e.name = zc.toStringUTF8(bname, bname.length);
            } else {
                e.name = zc.toString(bname, bname.length);      // Line 529
            }
        }
        /* snip */
        return e;
    }
    

    The only reason a NullPointerException would be thrown on this line would be if e, zc, or bname were null.

    e cannot be null because it is clearly instantiated in this method.

    zc cannot be null:

    public ZipFile(File file, int mode, Charset charset) throws IOException
    {
        /* snip */
        this.zc = ZipCoder.get(charset);
        /* snip */
    }
    
    static ZipCoder get(Charset charset) {
        return new ZipCoder(charset);
    }
    

    Which means that bname must be null, which is going to be pretty hard to debug. getEntryBytes is a native method:

    private static native byte[] getEntryBytes(long jzentry, int type);
    

    This is how I would proceed:

    • Figure out if it’s that particular zip file or all zip files. If it’s that particular zip file, try remaking it.
    • Update your version of Java, it’s possible that there was a bug with getEntryBytes that was fixed
    • Submit a bug report to Oracle
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a zip file compressed using Ionic zip . Before extracting I need
UPDATED WITH SOLUTION, see at bottom Requirement : Process a ZIP file in Java
I need help creating a self extracting zip file that does not display anything.
I am extracting the contents of a zip file with the following code: using(ZipArchive
I am experiencing a strange behavior with java.util.zip.* I have a zip file and
I'm looking for a way to access files within a zip file without extracting
I am extracting a zip file in PHP and trying to rename it to
I'm extracting a file from a zip archive using this code (omitting all the
I'm extracting a zip file and the problem is that the percentage calculation goes
My java program uploads a zip file from my system to FTP server. uploadfile()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.