UnZHGPPT opened a new issue, #10008: URL: https://github.com/apache/rocketmq/issues/10008
### 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 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: ```java 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 1. RemotingCommand.createRequestCommand(...) does not initialize the body field. 2. In updateAndCreateTopicList, the code calls: ```java final CreateTopicListRequestBody requestBody = CreateTopicListRequestBody.decode(request.getBody(), CreateTopicListRequestBody.class); ``` Since request.getBody() returns null, decode(...) returns null. 3. The next line unconditionally accesses: ```java List<TopicConfig> topicConfigList = requestBody.getTopicConfigList(); // NPE here ``` -- 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]
