szetszwo commented on code in PR #714:
URL: https://github.com/apache/ratis/pull/714#discussion_r947049950
##########
ratis-common/src/main/java/org/apache/ratis/protocol/RaftGroup.java:
##########
@@ -62,7 +62,12 @@ private RaftGroup(RaftGroupId groupId, Iterable<RaftPeer>
peers) {
this.peers = Collections.emptyMap();
} else {
final Map<RaftPeerId, RaftPeer> map = new HashMap<>();
- peers.forEach(p -> map.put(p.getId(), p));
+ peers.forEach(p -> {
+ Preconditions.assertTrue(!map.containsKey(p.getId()),
+ () -> "PeerId " + p.getId() + " has already appeared in this
group.");
Review Comment:
Let's use assertUnique, i.e.
```java
+++ b/ratis-common/src/main/java/org/apache/ratis/protocol/RaftGroup.java
@@ -61,6 +61,7 @@ public final class RaftGroup {
if (peers == null || !peers.iterator().hasNext()) {
this.peers = Collections.emptyMap();
} else {
+ Preconditions.assertUnique(peers);
final Map<RaftPeerId, RaftPeer> map = new HashMap<>();
peers.forEach(p -> map.put(p.getId(), p));
this.peers = Collections.unmodifiableMap(map);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]