From 963d50f97f90b65c1e2d4c3a6f7eef9baa19f789 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sun, 19 Jul 2026 16:39:25 +0000 Subject: [PATCH] Narrow catch clause in createArchive() to MavenArchiverException and ArchiverException Instead of catching the broad Exception type, catch only the specific exceptions that can actually be thrown: MavenArchiverException (checked exception from createArchive()) and ArchiverException (RuntimeException from addDirectory()). The TODO comment is removed since the exception types are now correctly scoped. --- .../java/org/apache/maven/plugins/jar/AbstractJarMojo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java b/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java index 10e00afb..1f4d855c 100644 --- a/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java +++ b/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java @@ -42,6 +42,7 @@ import org.apache.maven.shared.model.fileset.FileSet; import org.apache.maven.shared.model.fileset.util.FileSetManager; import org.codehaus.plexus.archiver.Archiver; +import org.codehaus.plexus.archiver.ArchiverException; import org.codehaus.plexus.archiver.jar.JarArchiver; /** @@ -288,8 +289,7 @@ public Path createArchive() throws MojoException { archiver.createArchive(session, project, archive); return jarFile; - } catch (Exception e) { - // TODO: improve error handling + } catch (MavenArchiverException | ArchiverException e) { throw new MojoException("Error assembling JAR", e); } }