Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #2129 from jglick/immutable-list-JENKINS-33467
[JENKINS-33467] Clarifying that CauseAction.getCauses is immutable
  • Loading branch information
jglick committed Mar 21, 2016
2 parents 697d4ad + 4adee75 commit a5124b5
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);
}

/**
Expand Down

0 comments on commit a5124b5

Please sign in to comment.