[ https://issues.apache.org/jira/browse/COMPRESS-696?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gary D. Gregory resolved COMPRESS-696. -------------------------------------- Fix Version/s: 1.28.0 Resolution: Fixed Hello [~sroughley] Thank you for your reports. I fixed this in git master with a -1 return value to match the end of the current method implementation and snapshot builds in Please verify your use case and close this ticket if appropriate. > 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)