apache / apache/maven-shared-jar

Resource leak in JarAnalyzer constructor if entries.sort() throws

Open Beginner friendly
#139 0 comments 0 reactions 0 assignees View on GitHub
bug priority:minor
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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.