Narrow catch clause in createArchive() - #561
Conversation
| return jarFile; | ||
| } catch (Exception e) { | ||
| // TODO: improve error handling | ||
| } catch (MavenArchiverException e) { |
There was a problem hiding this comment.
ArchiverException needs to be caught too. Just because it can propagate does not mean it should propagate
…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.
897796f to
963d50f
Compare
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.
| } catch (MavenArchiverException | ArchiverException e) { | ||
| throw new MojoException("Error assembling JAR", e); |
|
@elharo — reviewing as requested. The narrowing itself looks correct: My main point is sequencing rather than the diff: I'd suggest we merge #508 first and then re-evaluate #561. #508 rewrites If #561 does proceed independently of #508, two small follow-ups:
Both are moot if we take the #508-first route. |
Fixes #559
Replaces the broad
catch (Exception e)increateArchive()withcatch (MavenArchiverException | ArchiverException e), which are the specific checked exceptions declared byMavenArchiver.createArchive(). The// TODO: improve error handlingcomment is removed since the exception type is now correctly scoped.