You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "AlbumenJ (via GitHub)" <gi...@apache.org> on 2023/01/22 04:41:13 UTC

[GitHub] [dubbo] AlbumenJ commented on a diff in pull request #11360: fix channelHandlers has null object (#11357)

AlbumenJ commented on code in PR #11360:
URL: https://github.com/apache/dubbo/pull/11360#discussion_r1083390000


##########
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:
   ```suggestion
               handlers.stream().filter(Objects::nonNull).foreach(this.channelHandlers::add);
   ```



-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org