apache / apache/maven-shared-jar
Resource leak in JarAnalyzer constructor if entries.sort() throws
- Dominant language
- Java
- Stars
- 4
- Forks
- 9
- Avg merge
- 2h 46m
- Merged PRs (30d)
- 3
Description
In `JarAnalyzer.java`, the constructor opens a `JarFile` and then sorts entries:
```java
List entries = Collections.list(jarFile.entries());
entries.sort(Comparator.comparing(ZipEntry::getName)); // NPE if entry has null name
```
If any `JarEntry` has a `null` name (possible in malformed ZIPs), `Comparator.comparing` throws NPE before the `getManifest()` try/catch block is reached. The `JarFile` handle is never closed, causing a resource leak.
**Fix**: Either validate entry names before sorting, or use a null-safe comparator:
```java
entries.sort(Comparator.comparing(ZipEntry::getName, Comparator.nullsLast(Comparator.naturalOrder())));
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in JarAnalyzer.java at the constructor, where entries are collected and sorted before the getManifest() try/catch block. Inspect how malformed entries with null names are handled and whether the existing test suite covers this path. Done means sorting cannot bypass JarFile cleanup when an entry name causes an exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100