Skip to content

Commit

Permalink
Don't catch NPE (SpotBugs).
Browse files Browse the repository at this point in the history
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 dfc8604
Showing 1 changed file with 4 additions and 3 deletions.
Expand Up @@ -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);
}
Expand Down

0 comments on commit dfc8604

Please sign in to comment.