Skip to content

Commit

Permalink
[JENKINS-33467] Clarifying that CauseAction.getCauses is immutable an…
Browse files Browse the repository at this point in the history
…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 63886be
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions core/src/main/java/hudson/model/CauseAction.java
Expand Up @@ -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.

}

/**
Expand Down

0 comments on commit 63886be

Please sign in to comment.