-
Notifications
You must be signed in to change notification settings - Fork 12k
Description
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
version: rocketmq-all-5.4.0
link: https://github.com/apache/rocketmq/archive/refs/tags/rocketmq-all-5.4.0.zip
JDK Version
Java version: 1.8.0_452
Build tool: Apache Maven 3.9.1
Describe the Bug
A NullPointerException occurs when invoking AdminBrokerProcessor.processRequest with a RemotingCommand created via RemotingCommand.createRequestCommand(...) that has a null body. The issue arises because the method CreateTopicListRequestBody.decode(...) returns null when the input byte array is null, and the subsequent call to requestBody.getTopicConfigList() dereferences this null value.
Steps to Reproduce
Test Code:
package org.apache.rocketmq.broker.processor;
import org.apache.rocketmq.broker.processor.AdminBrokerProcessor;
import org.junit.Test;
import org.apache.rocketmq.broker.BrokerController;
import io.netty.channel.ChannelHandlerContext;
import org.apache.rocketmq.remoting.protocol.RemotingCommand;
import org.apache.rocketmq.remoting.protocol.RequestCode;
import org.apache.rocketmq.common.BrokerConfig;
import org.apache.rocketmq.common.MixAll;
import org.apache.rocketmq.remoting.netty.NettyClientConfig;
import org.apache.rocketmq.remoting.netty.NettyServerConfig;
import org.apache.rocketmq.store.config.MessageStoreConfig;
public class TestClass {
@Test(timeout=3000)
public void test() throws Throwable {
BrokerConfig brokerConfig = new BrokerConfig();
NettyServerConfig nettyServerConfig = new NettyServerConfig();
NettyClientConfig nettyClientConfig = new NettyClientConfig();
MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
BrokerController brokerController = new BrokerController(brokerConfig, nettyServerConfig, nettyClientConfig, messageStoreConfig);
AdminBrokerProcessor adminBrokerProcessor0 = new AdminBrokerProcessor(brokerController);
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UPDATE_AND_CREATE_TOPIC_LIST, null);
adminBrokerProcessor0.processRequest((ChannelHandlerContext) null, request);
}
}Execution Result:
JUnit version 4.13.2
.E
Time: 0.869
There was 1 failure:
1) test(org.apache.rocketmq.broker.processor.TestClass)
java.lang.NullPointerException
at org.apache.rocketmq.broker.processor.AdminBrokerProcessor.updateAndCreateTopicList(AdminBrokerProcessor.java:636)
at org.apache.rocketmq.broker.processor.AdminBrokerProcessor.processRequest(AdminBrokerProcessor.java:269)
at org.apache.rocketmq.broker.processor.TestClass.test(TestClass.java:24)
FAILURES!!!
Tests run: 1, Failures: 1
What Did You Expect to See?
The method should either:
- Validate that the request body is non-null before decoding, or
- Handle the case where the decoded CreateTopicListRequestBody is null gracefully (e.g., return an error response).
What Did You See Instead?
A NPE is thrown:
java.lang.NullPointerException
at org.apache.rocketmq.broker.processor.AdminBrokerProcessor.updateAndCreateTopicList(AdminBrokerProcessor.java:636)
at org.apache.rocketmq.broker.processor.AdminBrokerProcessor.processRequest(AdminBrokerProcessor.java:269)
at org.apache.rocketmq.broker.processor.TestClass.test(TestClass.java:24)
Additional Context
Root Cause Analysis
-
RemotingCommand.createRequestCommand(...) does not initialize the body field.
-
In updateAndCreateTopicList, the code calls:
final CreateTopicListRequestBody requestBody = CreateTopicListRequestBody.decode(request.getBody(), CreateTopicListRequestBody.class);Since request.getBody() returns null, decode(...) returns null.
- The next line unconditionally accesses:
List<TopicConfig> topicConfigList = requestBody.getTopicConfigList(); // NPE here