From eed7a5f96b504b45b15d908e1bd07ceaa942938b Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 9 Mar 2023 15:45:55 +0100 Subject: [PATCH] Avoid possible NPE, fixes #795 --- .../logging/smart/LoggingExecutionListener.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/daemon/src/main/java/org/mvndaemon/mvnd/logging/smart/LoggingExecutionListener.java b/daemon/src/main/java/org/mvndaemon/mvnd/logging/smart/LoggingExecutionListener.java index 3fe2a20ac..a3285b199 100644 --- a/daemon/src/main/java/org/mvndaemon/mvnd/logging/smart/LoggingExecutionListener.java +++ b/daemon/src/main/java/org/mvndaemon/mvnd/logging/smart/LoggingExecutionListener.java @@ -23,6 +23,7 @@ import org.apache.maven.execution.ExecutionEvent; import org.apache.maven.execution.ExecutionListener; +import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.ProjectExecutionEvent; import org.apache.maven.execution.ProjectExecutionListener; @@ -58,12 +59,23 @@ public void afterProjectExecutionSuccess(ProjectExecutionEvent projectExecutionE @Override public void afterProjectExecutionFailure(ProjectExecutionEvent projectExecutionEvent) { MavenSession session = projectExecutionEvent.getSession(); + boolean halted; + // The ReactorBuildStatus is only available if the SmartBuilder is used ReactorBuildStatus status = (ReactorBuildStatus) session.getRepositorySession().getData().get(ReactorBuildStatus.class); + if (status != null) { + halted = status.isHalted(); + } else { + // assume sensible default + Throwable t = projectExecutionEvent.getCause(); + halted = (t instanceof RuntimeException || !(t instanceof Exception)) + || !MavenExecutionRequest.REACTOR_FAIL_NEVER.equals(session.getReactorFailureBehavior()) + && !MavenExecutionRequest.REACTOR_FAIL_AT_END.equals(session.getReactorFailureBehavior()); + } Throwable cause = projectExecutionEvent.getCause(); buildEventListener.executionFailure( projectExecutionEvent.getProject().getArtifactId(), - status.isHalted(), + halted, cause != null ? cause.toString() : null); }