Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readLine from zip file,throw NPE when file contains blank lines #35

Closed
huifrank opened this issue Aug 5, 2019 · 5 comments
Closed

readLine from zip file,throw NPE when file contains blank lines #35

huifrank opened this issue Aug 5, 2019 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@huifrank
Copy link

huifrank commented Aug 5, 2019

here is my test Code

 public static void main(String[] args) throws IOException {
        ZipFile zipFile = new ZipFile("/Users/lihui/IdeaProjects/nettydemo/src/main/resources/a.txt.zip");
        List<FileHeader> fileHeaders = zipFile.getFileHeaders();
        FileHeader fileHeader = fileHeaders.get(0);
        ZipInputStream inputStream = zipFile.getInputStream(fileHeader);

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));

        String line;
        while ( (line=bufferedReader.readLine())!=null  ){
            System.out.println(line);
        }

    }

and a.txt.zip is Zip file of this

1234
12124

5678
123123

Note that there have a blank line in a.txt

Then run this code , program will throw a NPE after print all lines.
and this code work fine when file contains no blank line.

@srikanth-lingala
Copy link
Owner

In my case it worked fine. I used the same code as yours (only changed the path to the zip file):

ZipFile zipFile = new ZipFile("/Users/slingala/Downloads/a.txt.zip");
    List<FileHeader> fileHeaders = zipFile.getFileHeaders();
    FileHeader fileHeader = fileHeaders.get(0);
    ZipInputStream inputStream = zipFile.getInputStream(fileHeader);

    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));

    String line;
    while ( (line=bufferedReader.readLine())!=null  ){
      System.out.println(line);
    }

And attached (at the bottom of this post) is the zip file I used. I ran the code and the output is as below:

1234
12124

5678
123123

I ran the code on a Mac with JDK 8. Can you please try with the attached zip file? I created this zip file on my machine with the text from your post. If you are still stuck, please attach the zip file you created.

a.txt.zip

@huifrank
Copy link
Author

huifrank commented Aug 5, 2019

@srikanth-lingala
Thank you for you Answer。
I am kind of understand why in my case it throws NPE ,and your is find .

in you txt ,there have a blank line in the end, and mine is nothing.
here is my test file

thanks again
a.txt.zip

@srikanth-lingala
Copy link
Owner

Thanks for the hint. I was able to reproduce it without the empty line at the end. I will look into it.

@srikanth-lingala
Copy link
Owner

Issue fixed. Will include in the next release.

@srikanth-lingala
Copy link
Owner

Fixed in v2.1.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants