Skip to content

[Bug] NullPointerException in ScheduleMessageService$HandlePutResultTask.run at line 562 #10009

@UnZHGPPT

Description

@UnZHGPPT

Before Creating the Bug Report

  • I found a bug, not just asking a question, which should be created in GitHub Discussions.

  • I have searched the GitHub Issues and GitHub Discussions of this repository and believe that this is not a duplicate.

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions