apache / apache/maven-jar-plugin

Catch Exception is too broad in createArchive()

Open
#559 0 comments 0 reactions 1 assignee Claimed by @elharo View on GitHub
Dominant language
Java
Stars
92
Forks
84
Avg merge
19h 45m
Merged PRs (30d)
6

Description

## Bug

`createArchive()` catches `Exception` in its error handling block, which is broader than necessary and can swallow unrelated exceptions.

## Location

`AbstractJarMojo.java:291-294`:

```java
} catch (Exception e) {
// TODO: improve error handling
throw new MojoException("Error assembling JAR", e);
}
```

## Problem

Catching `Exception` will also catch unchecked runtime exceptions (e.g. `NullPointerException`, `ArrayIndexOutOfBoundsException`) and even `Throwable` subtypes like `Error` (though `Error` is not a subclass of `Exception`). The existing `// TODO: improve error handling` comment acknowledges this. Consider narrowing the catch clause to the specific exception types thrown by the operations in the try block.

## Suggested fix

Catch `IOException` and `MavenArchiverException` (or other specific exception types from the archiver API) instead of the generic `Exception`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.