Skip to content

Commit

Permalink
Avoid possible NPE, fixes apache#795
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Mar 9, 2023
1 parent c1fd7e6 commit eed7a5f
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit eed7a5f

Please sign in to comment.