Skip to content

Commit de95488

Browse files
committed
Avoid creating cycles with Throwable.addSuppressed
1 parent 6bdb5a5 commit de95488

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/main/java/org/jenkinsci/plugins/workflow/cps/CpsStepContext.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.google.common.util.concurrent.SettableFuture;
3131
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
3232
import groovy.lang.Closure;
33-
import hudson.Main;
3433
import hudson.model.Descriptor;
3534
import hudson.model.Result;
3635
import hudson.util.DaemonThreadFactory;
@@ -66,6 +65,7 @@
6665
import java.util.function.Function;
6766
import java.util.logging.Level;
6867
import java.util.logging.Logger;
68+
import java.util.stream.Stream;
6969
import jenkins.model.CauseOfInterruption;
7070
import jenkins.util.ContextResettingExecutorService;
7171
import org.codehaus.groovy.runtime.InvokerInvocationException;
@@ -345,12 +345,16 @@ private void completed(@NonNull Outcome newOutcome) {
345345
LOGGER.log(Level.FINE, "earlier success: {0}", outcome.getNormal());
346346
}
347347
}
348-
if (failure != null && earlierFailure != null) {
348+
if (failure != null && earlierFailure != null && !refersTo(failure, earlierFailure)) {
349349
earlierFailure.addSuppressed(failure);
350350
}
351351
}
352352
}
353353

354+
private static boolean refersTo(Throwable t1, Throwable t2) {
355+
return t1 == t2 || t1.getCause() != null && refersTo(t1.getCause(), t2) || Stream.of(t1.getSuppressed()).anyMatch(t3 -> refersTo(t3, t2));
356+
}
357+
354358
/**
355359
* When this step context has completed execution (successful or otherwise), plan the next action.
356360
*/

0 commit comments

Comments
 (0)