Skip to content
Permalink
Browse files
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.
  • Loading branch information
garydgregory committed Dec 27, 2021
1 parent cd3769c commit dfc860468bf028a1ac762473e03872b1b7dbb1b6
Showing 1 changed file with 4 additions and 3 deletions.
@@ -134,12 +134,13 @@ public static <T> T requireNonNull(final T obj, final Supplier<String> messageSu
* 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);
}

0 comments on commit dfc8604

Please sign in to comment.