Skip to content

Commit

Permalink
[FIXED JENKINS-40281] Do not try to mutate the result of getActions(C…
Browse files Browse the repository at this point in the history
…lass).
  • Loading branch information
jglick committed Dec 8, 2016
1 parent 9172bca commit 5c79beb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/src/main/java/hudson/model/Run.java
Expand Up @@ -480,6 +480,7 @@ public void setResult(@Nonnull Result r) {
public @Nonnull List<BuildBadgeAction> getBadgeActions() {
List<BuildBadgeAction> r = getActions(BuildBadgeAction.class);
if(isKeepLog()) {
r = new ArrayList<>(r);
r.add(new KeepLogBuildBadge());
}
return r;
Expand Down
14 changes: 14 additions & 0 deletions test/src/test/java/hudson/model/RunTest.java
Expand Up @@ -26,6 +26,8 @@
import java.net.HttpURLConnection;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import static org.junit.Assert.*;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
Expand Down Expand Up @@ -59,4 +61,16 @@ public class RunTest {
j.createWebClient().assertFails("job/stuff/1/nonexistent", HttpURLConnection.HTTP_NOT_FOUND);
}

@Issue("JENKINS-40281")
@Test public void getBadgeActions() throws Exception {
FreeStyleProject p = j.createFreeStyleProject();
FreeStyleBuild b = j.buildAndAssertSuccess(p);
assertEquals(0, b.getBadgeActions().size());
assertTrue(b.canToggleLogKeep());
b.keepLog();
List<BuildBadgeAction> badgeActions = b.getBadgeActions();
assertEquals(1, badgeActions.size());
assertEquals(Run.KeepLogBuildBadge.class, badgeActions.get(0).getClass());
}

}

0 comments on commit 5c79beb

Please sign in to comment.