KamToHung commented on code in PR #11360:
URL: https://github.com/apache/dubbo/pull/11360#discussion_r1083398684
##########
dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/ChannelHandlerDispatcher.java:
##########
@@ -41,12 +43,15 @@ public ChannelHandlerDispatcher() {
}
public ChannelHandlerDispatcher(ChannelHandler... handlers) {
+ // if varargs is used, the type of handlers is ChannelHandler[] and it
is not null
+ // so we should filter the null object
this(handlers == null ? null : Arrays.asList(handlers));
}
public ChannelHandlerDispatcher(Collection<ChannelHandler> handlers) {
if (CollectionUtils.isNotEmpty(handlers)) {
- this.channelHandlers.addAll(handlers);
+ // filter null object
+
this.channelHandlers.addAll(handlers.stream().filter(Objects::nonNull).collect(Collectors.toSet()));
Review Comment:
the channelHandlers is a CopyOnWriteArraySet, when we edit the value ,
CopyOnWriteArraySet will create a new list, so I think that we should use addAll
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]