Steve Roughley created COMPRESS-696:
---------------------------------------
Summary: 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
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)