You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/12/27 14:45:52 UTC

[commons-release-plugin] 01/02: Don't catch NPE (SpotBugs).

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-release-plugin.git

commit dfc860468bf028a1ac762473e03872b1b7dbb1b6
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Dec 27 09:44:48 2021 -0500

    Don't catch NPE (SpotBugs).
    
    Reimplement catch and rethrow NPE in the style of
    Objects#requireNonNull() and don't log NPE, just percolate as Mojo
    exception.
---
 .../java/org/apache/commons/release/plugin/SharedFunctions.java    | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/release/plugin/SharedFunctions.java b/src/main/java/org/apache/commons/release/plugin/SharedFunctions.java
index 770a786..6861cda 100755
--- a/src/main/java/org/apache/commons/release/plugin/SharedFunctions.java
+++ b/src/main/java/org/apache/commons/release/plugin/SharedFunctions.java
@@ -134,12 +134,13 @@ public final class SharedFunctions {
      *      purpose of bubbling the exception up to Maven properly.
      */
     public static void initDirectory(final Log log, final File workingDirectory) throws MojoExecutionException {
+        final String format = "Unable to remove directory %s: %s";
+        requireNonNull(workingDirectory, () -> String.format(format, workingDirectory));
         if (workingDirectory.exists()) {
             try {
                 FileUtils.deleteDirectory(workingDirectory);
-            } catch (final IOException | NullPointerException e) {
-                final String message = String.format("Unable to remove directory %s: %s", workingDirectory,
-                        e.getMessage());
+            } catch (final IOException e) {
+                final String message = String.format(format, workingDirectory, e.getMessage());
                 log.error(message);
                 throw new MojoExecutionException(message, e);
             }