Skip to content

Commit

Permalink
[JENKINS-72409] StackOverflowError with Rebuild v330.v645b_7df10e2a
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Mar 5, 2024
1 parent d8ec885 commit 1902e9e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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]));
}
}

0 comments on commit 1902e9e

Please sign in to comment.