Skip to content

channelHandlers has null object #11357

@KamToHung

Description

@KamToHung
  • I have searched the issues of this repository and believe that this is not a duplicate.

Environment

  • Dubbo version: 3.2
  • Operating System version: macOS Big Sur
  • Java version: 8

Steps to reproduce this issue

  1. simple test
public class NPETest {

    protected WorldHandler handler = new WorldHandler();

    @Test
    void handlerIsNull() throws RemotingException {
        Exchangers.bind("",null, handler);
    }

}
  1. handler is not null in this step
    public ChannelHandlerDispatcher(ChannelHandler... handlers) {
        this(handlers == null ? null : Arrays.asList(handlers));
    }
  1. channelHandlers will add a null handler
    public ChannelHandlerDispatcher(Collection<ChannelHandler> handlers) {
        if (CollectionUtils.isNotEmpty(handlers)) {
            this.channelHandlers.addAll(handlers);
        }
    }
  1. connected, disconnected, sent and caught method will NPE

Expected Behavior

channelHandlers have no null object

Actual Behavior

channelHandlers have null object

reason

   public ChannelHandlerDispatcher(ChannelHandler... handlers) {
        this(handlers == null ? null : Arrays.asList(handlers));
    }

   public ChannelHandlerDispatcher(Collection<ChannelHandler> handlers) {
        if (CollectionUtils.isNotEmpty(handlers)) {
            this.channelHandlers.addAll(handlers);
        }
    }

if handlers is null, it will cast to ChannelHandler and use the first method then handlers is not null

we can filter the null object when add to channelHandlers

Can I fix it?

Metadata

Metadata

Assignees

Labels

type/bugBugs to being fixed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions