Skip to content

Commit

Permalink
#6529: make a copy in getters
Browse files Browse the repository at this point in the history
  • Loading branch information
jaroslawmalekcodete committed Dec 19, 2017
1 parent 4f6ed73 commit 78d0710
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.ArrayList;
import java.util.List;

import static java.util.Arrays.asList;
import static java.util.Collections.synchronizedList;

public class KernelSocketsTest extends KernelSockets {
Expand All @@ -39,11 +40,15 @@ public void send(Message message) {
}

public List<Message> getPublishedMessages() {
return new ArrayList<>(publishedMessages);
return copy(this.publishedMessages);
}

public List<Message> getSentMessages() {
return new ArrayList<>(sentMessages);
return copy(this.sentMessages);
}

private List<Message> copy(List<Message> list) {
return asList(list.toArray(new Message[0]));
}

public void clear() {
Expand Down

0 comments on commit 78d0710

Please sign in to comment.