Skip to content
Permalink
Browse files
[JENKINS-33467] Clarifying that CauseAction.getCauses is immutable an…
…d you should construct the action with the causes you want.

(cherry picked from commit 4adee75)
  • Loading branch information
jglick authored and olivergondza committed Apr 25, 2016
1 parent 916e759 commit 63886be9f75c6f538b9401d9cb445b701b1f017c
Showing with 9 additions and 2 deletions.
  1. +9 −2 core/src/main/java/hudson/model/CauseAction.java
@@ -82,14 +82,21 @@ public CauseAction(Collection<? extends Cause> causes) {
public CauseAction(CauseAction ca) {
addCauses(ca.getCauses());
}


/**
* Lists all causes of this build.
* Note that the current implementation does not preserve insertion order of duplicates.
* @return an immutable list;
* to create an action with multiple causes use either of the constructors that support this;
* to append causes retroactively to a build you must create a new {@link CauseAction} and replace the old
*/
@Exported(visibility=2)
public List<Cause> getCauses() {
List<Cause> r = new ArrayList<>();
for (Map.Entry<Cause,Integer> entry : causeBag.entrySet()) {
r.addAll(Collections.nCopies(entry.getValue(), entry.getKey()));
}
return r;
return Collections.unmodifiableList(r);

This comment has been minimized.

Copy link
@amuniz

amuniz Jul 6, 2016

Member

FTR, this was a backward incompatible change and should not have been backported.

This comment has been minimized.

Copy link
@oleg-nenashev

oleg-nenashev Jul 6, 2016

Member

Actually there was no point in modifying the original list (it's a copy of the real data), so this backport just ensures the correct propagation of the problem.

}

/**

0 comments on commit 63886be

Please sign in to comment.