From 1902e9ead5e4a85d6088657a89e369b445d957b3 Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Tue, 5 Mar 2024 11:18:38 -0800 Subject: [PATCH] [JENKINS-72409] `StackOverflowError` with Rebuild v330.v645b_7df10e2a --- .../trigger/GerritRebuildValidator.java | 3 +- .../trigger/GerritRebuildValidatorTest.java | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/GerritRebuildValidatorTest.java diff --git a/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/GerritRebuildValidator.java b/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/GerritRebuildValidator.java index f3808c23a..7e2b838e0 100644 --- a/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/GerritRebuildValidator.java +++ b/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/GerritRebuildValidator.java @@ -42,7 +42,8 @@ public class GerritRebuildValidator extends RebuildValidator { @Override public boolean isApplicable(Run build) { - return (build.getCause(GerritCause.class) != null); + // Build#getActions is deprecated but the only way to prevent a stack overflow here + return build.getActions().stream().anyMatch(it -> it instanceof GerritCause); } } diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/GerritRebuildValidatorTest.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/GerritRebuildValidatorTest.java new file mode 100644 index 000000000..583bb48e2 --- /dev/null +++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/GerritRebuildValidatorTest.java @@ -0,0 +1,32 @@ +package com.sonyericsson.hudson.plugins.gerrit.trigger; + +import static org.junit.Assert.assertNotNull; + +import hudson.ExtensionList; +import hudson.model.Action; +import hudson.model.FreeStyleProject; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.Issue; +import org.jvnet.hudson.test.JenkinsRule; + +/** + * Tests for {@link GerritRebuildValidator}. + */ +public class GerritRebuildValidatorTest { + + /** + * An instance of {@link JenkinsRule}. + */ + // CS IGNORE VisibilityModifier FOR NEXT 2 LINES. REASON: JenkinsRule. + @Rule + public final JenkinsRule j = new JenkinsRule(); + + @Issue("JENKINS-72409") + @Test + public void testRebuildValidatorStackOverflow() throws Exception { + assertNotNull(ExtensionList.lookupSingleton(GerritRebuildValidator.class)); + FreeStyleProject p = j.createFreeStyleProject(); + j.assertBuildStatusSuccess(p.scheduleBuild2(0, null, new Action[0])); + } +}