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

   ### 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
   
   A NullPointerException occurs in 
ScheduleMessageService$HandlePutResultTask.run() at line 562 because the code 
assumes that ScheduleMessageService.this.deliverPendingTable.get(level) always 
returns a non-null LinkedBlockingQueue. However, if no queue has been 
initialized for the given level, get() returns null, and subsequent operations  
on this null reference trigger an NPE.
   
   ### Steps to Reproduce
   
   Test Code:
   
   ```java
   package org.apache.rocketmq.broker.schedule;
   import org.apache.rocketmq.store.config.MessageStoreConfig;
   import org.apache.rocketmq.auth.config.AuthConfig;
   import org.apache.rocketmq.remoting.netty.NettyClientConfig;
   import org.apache.rocketmq.broker.schedule.ScheduleMessageService;
   import org.apache.rocketmq.broker.BrokerController;
   import org.junit.Test;
   import org.apache.rocketmq.remoting.netty.NettyServerConfig;
   import org.apache.rocketmq.common.BrokerConfig;
   
   public class TestClass {
       @Test(timeout=3000)
       public void test() throws Throwable {
           BrokerConfig brokerConfig0 = new BrokerConfig();
           NettyServerConfig nettyServerConfig0 = new NettyServerConfig();
           NettyClientConfig nettyClientConfig0 = new NettyClientConfig();
           MessageStoreConfig messageStoreConfig0 = new MessageStoreConfig();
           BrokerController brokerController0 = new 
BrokerController(brokerConfig0, nettyServerConfig0, nettyClientConfig0, 
messageStoreConfig0, (AuthConfig) null);
           ScheduleMessageService scheduleMessageService0 = new 
ScheduleMessageService(brokerController0);
           // Removed direct access to private field deliverPendingTable
           ScheduleMessageService.HandlePutResultTask 
scheduleMessageService_HandlePutResultTask0 = scheduleMessageService0.new 
HandlePutResultTask(3703);
           scheduleMessageService_HandlePutResultTask0.run();
       }
   }
   ```
   
   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 HandlePutResultTask.run() method should handle the case where no pending 
queue exists for the given level—either by skipping processing or lazily 
initializing an empty queue—without throwing an exception.
   
   ### 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
   
   _No response_


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