Skip to content

Catch Exception is too broad in createArchive() #559

Description

@elharo

Bug

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

Location

AbstractJarMojo.java:291-294:

} 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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions