[ 
https://issues.apache.org/jira/browse/COMPRESS-696?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17938243#comment-17938243
 ] 

Steve Roughley commented on COMPRESS-696:
-----------------------------------------

Thank you for this rapid fix.

Steve

> ZipArchiveInputStream.getCompressedCount() throws NullPointerException if 
> called before getNextEntry()
> ------------------------------------------------------------------------------------------------------
>
>                 Key: COMPRESS-696
>                 URL: https://issues.apache.org/jira/browse/COMPRESS-696
>             Project: Commons Compress
>          Issue Type: Bug
>          Components: Archivers
>    Affects Versions: 1.27.1
>            Reporter: Steve Roughley
>            Assignee: Gary D. Gregory
>            Priority: Major
>             Fix For: 1.28.0
>
>
> Calling ZipArchiveInputStream.getCompressedCount() throws 
> NullPointerException if no prior call to #getNextEntry() has been made.
>  
> This applies to any Zip file, e.g.
> ```
> InputStream in = Files.newInputStream(Path.of("path/to/zip/archive.zip")); // 
> Any will do
> ZipArchiveInputStream zis = new ZipArchiveInputStream(in);
> zis.getCompressedCount(); // Throws NPE
> ```
> Whereas:
> ```
> InputStream in = Files.newInputStream(Path.of("path/to/zip/archive.zip")); // 
> Any will do
> ZipArchiveInputStream zis = new ZipArchiveInputStream(in);
> zis.getNextEntry();
> zis.getCompressedCount(); // Does not throw NPE
> ```
> This is due to the first line of the implementation of #getCompressedCount() 
> at 
> https://github.com/apache/commons-compress/blob/d9166a57da9f412657482161fd2758538c11e8d9/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java#L629:
> ```
>         final int method = current.entry.getMethod();
> ```
> The field `current` is `null` prior to first call of `getNextEntry()`.  A 
> simple null check prior to this line would fix, e.g.:
> ```
> if (current == null) {
>     return 0L;
> }
> ...
> ```
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to