From 9ef317a3e0a94dd74f1dbae5d9bab0fb6d8e01a0 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Mon, 7 Aug 2023 17:02:13 -0400 Subject: [PATCH] NPE in `WithMavenStepExecutionCallBack.finished` (#682) --- .../pipeline/maven/WithMavenStepExecution2.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/WithMavenStepExecution2.java b/jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/WithMavenStepExecution2.java index dfebf49b..2a2299a4 100644 --- a/jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/WithMavenStepExecution2.java +++ b/jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/WithMavenStepExecution2.java @@ -87,6 +87,7 @@ import edu.umd.cs.findbugs.annotations.CheckForNull; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; +import hudson.Functions; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -1107,8 +1108,14 @@ private WithMavenStepExecutionCallBack(@NonNull FilePath tempBinDir, @NonNull Li @Override protected void finished(StepContext context) throws Exception { + TaskListener listener = context.get(TaskListener.class); if (tempBinDir == null) { // normal case - tempBinDir = context.get(FilePath.class).child(tempBinDirPath); + FilePath ws = context.get(FilePath.class); + if (ws == null) { + listener.getLogger().println("Missing agent to clean up " + tempBinDirPath); + return; + } + tempBinDir = ws.child(tempBinDirPath); } // else resuming old build mavenSpyLogProcessor.processMavenSpyLogs(context, tempBinDir, options, mavenPublisherStrategy); @@ -1116,12 +1123,11 @@ protected void finished(StepContext context) throws Exception { try { tempBinDir.deleteRecursive(); } catch (IOException | InterruptedException e) { - BuildListener listener = context.get(BuildListener.class); try { if (e instanceof IOException) { Util.displayIOException((IOException) e, listener); // Better IOException display on windows } - e.printStackTrace(listener.fatalError("Error deleting temporary files")); + Functions.printStackTrace(e, listener.fatalError("Error deleting temporary files")); } catch (Throwable t) { t.printStackTrace(); }