UnZHGPPT opened a new issue, #10010:
URL: https://github.com/apache/rocketmq/issues/10010

   ### Before Creating the Bug Report
   
   - [x] I found a bug, not just asking a question, which should be created in 
[GitHub Discussions](https://github.com/apache/rocketmq/discussions).
   
   - [x] I have searched the [GitHub 
Issues](https://github.com/apache/rocketmq/issues) and [GitHub 
Discussions](https://github.com/apache/rocketmq/discussions)  of this 
repository and believe that this is not a duplicate.
   
   - [x] I have confirmed that this bug belongs to the current repository, not 
other repositories of RocketMQ.
   
   
   ### Runtime platform environment
   
   OS name: "linux", version: "5.15.0-138-generic", arch: "amd64", family: 
"unix"
   
   ### RocketMQ version
   
   rocketmq-all-5.4.0
   
   ### JDK Version
   
   Apache Maven 3.9.1
   Java version: 1.8.0_452, vendor: Private Build, runtime: 
/usr/lib/jvm/java-8-openjdk-amd64/jre
   
   ### Describe the Bug
   
   In the method 
NettyRemotingClient.NettyConnectManageHandler.channelActive(ChannelHandlerContext
 ctx), the code directly accesses ctx.channel() and calls .id() on it without 
verifying that the channel is non-null:
   
   ```java
   LOGGER.info("NETTY CLIENT PIPELINE: ACTIVE, {}, channelId={}", 
remoteAddress, ctx.channel().id());
   ```
   
   However, if the ChannelHandlerContext is constructed with a null channel 
(e.g., via SimpleChannelHandlerContext), ctx.channel() returns null, leading to 
a NullPointerException when invoking .id().
   
   This also affects the constructor of SimpleChannelHandlerContext, which does 
not validate its input channel, allowing null propagation.
   
   ### Steps to Reproduce
   
   Test Code:
   
   ```java
   package org.apache.rocketmq.remoting.netty;
   import org.apache.rocketmq.remoting.netty.NettyClientConfig;
   import io.netty.channel.DefaultChannelId;
   import io.netty.channel.ChannelHandler;
   import org.apache.rocketmq.remoting.netty.NettyRemotingClient;
   import org.junit.Test;
   import io.netty.channel.ChannelHandlerContext;
   import io.netty.channel.ChannelId;
   import org.apache.rocketmq.proxy.service.channel.SimpleChannelHandlerContext;
   import io.netty.channel.embedded.EmbeddedChannel;
   
   public class TestClass {
       @Test(timeout=3000)
       public void test() throws Throwable {
           NettyClientConfig nettyClientConfig0 = new NettyClientConfig();
           NettyRemotingClient nettyRemotingClient0 = new 
NettyRemotingClient(nettyClientConfig0);
           NettyRemotingClient.NettyConnectManageHandler 
nettyRemotingClient_NettyConnectManageHandler0 = nettyRemotingClient0.new 
NettyConnectManageHandler();
           DefaultChannelId defaultChannelId0 = DefaultChannelId.newInstance();
           ChannelHandler[] channelHandlerArray0 = new ChannelHandler[0];
           EmbeddedChannel embeddedChannel0 = null;
           SimpleChannelHandlerContext simpleChannelHandlerContext0 = new 
SimpleChannelHandlerContext(embeddedChannel0);
           
nettyRemotingClient_NettyConnectManageHandler0.channelActive(simpleChannelHandlerContext0);
       }
   }
   ```
   
   Execution Result
   
   ```
   JUnit version 4.13.2
   .E
   Time: 0.856
   There was 1 failure:
   1) test(org.apache.rocketmq.broker.schedule.TestClass)
   java.lang.NullPointerException
        at 
org.apache.rocketmq.broker.schedule.ScheduleMessageService$HandlePutResultTask.run(ScheduleMessageService.java:562)
        at org.apache.rocketmq.broker.schedule.TestClass.test(TestClass.java:22)
   
   FAILURES!!!
   Tests run: 1,  Failures: 1
   ```
   
   
   ### What Did You Expect to See?
   
   The channelActive method should gracefully handle cases where the channel is 
null (e.g., log a warning or skip processing), or SimpleChannelHandlerContext 
should reject null channels at construction time.
   
   ### What Did You See Instead?
   
   A NullPointerException is thrown:
   
   ```
   java.lang.NullPointerException
        at 
org.apache.rocketmq.broker.schedule.ScheduleMessageService$HandlePutResultTask.run(ScheduleMessageService.java:562)
        at org.apache.rocketmq.broker.schedule.TestClass.test(TestClass.java:22)
   ```
   
   ### Additional Context
   
   I think maybe we can add a null check or default-init in the 
SimpleChannelHandlerContext(...)?


-- 
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]

Reply via email to