Narrow catch clause in createArchive()#561
Open
elharo wants to merge 1 commit into
Open
Conversation
elharo
commented
Jul 19, 2026
| return jarFile; | ||
| } catch (Exception e) { | ||
| // TODO: improve error handling | ||
| } catch (MavenArchiverException e) { |
Contributor
Author
There was a problem hiding this comment.
ArchiverException needs to be caught too. Just because it can propagate does not mean it should propagate
elharo
marked this pull request as draft
July 19, 2026 16:32
…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.
elharo
force-pushed
the
fix-catch-exception
branch
from
July 19, 2026 16:39
897796f to
963d50f
Compare
elharo
marked this pull request as ready for review
July 19, 2026 16:45
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #559 by narrowing exception handling in AbstractJarMojo#createArchive() so that it no longer catches a generic Exception while assembling the JAR, improving error specificity and avoiding unintended swallowing of unrelated runtime failures.
Changes:
- Replace
catch (Exception e)with a narrower multi-catch forMavenArchiverExceptionandArchiverException. - Remove the
// TODO: improve error handlingcomment now that the catch block is scoped to archiver-related exceptions. - Add the required
ArchiverExceptionimport.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+292
to
293
| } catch (MavenArchiverException | ArchiverException e) { | ||
| throw new MojoException("Error assembling JAR", e); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #559
Replaces the broad
catch (Exception e)increateArchive()withcatch (MavenArchiverException e), which is the specific checked exception declared byMavenArchiver.createArchive(). The// TODO: improve error handlingcomment is removed since the exception type is now correctly scoped.