zjncs opened a new pull request, #11127:
URL: https://github.com/apache/rocketmq/pull/11127
## Motivation
The order topic conf is a manually maintained name server kv config
(`NAMESPACE_ORDER_TOPIC_CONFIG`, set via `updateKvConfig`) that is delivered to
clients inside `TopicRouteData` when `orderMessageEnable` is on.
`MQClientInstance.topicRouteData2TopicPublishInfo` parses each
`brokerName:queueNums` segment with `split(":")` and
`Integer.parseInt(item[1])` without any validation, so a single typo in the kv
value — a segment without `:", or a non-numeric queue count — makes the
conversion throw `ArrayIndexOutOfBoundsException` or `NumberFormatException`:
```java
String[] item = broker.split(":");
int nums = Integer.parseInt(item[1]); // AIOOBE / NFE on a malformed
segment
```
These unchecked exceptions escape `updateTopicRouteInfoFromNameServer`,
whose inner catch only handles `MQClientException`/`RemotingException`:
- the producer send path (`tryToFindTopicPublishInfo` → route refresh)
surfaces a raw `NumberFormatException`/`ArrayIndexOutOfBoundsException` out of
`send()` instead of an `MQClientException`;
- the periodic route refresh task aborts the whole per-cycle topic loop, so
**other, correctly configured topics lose their route refresh too**;
- the failure happens before `topicRouteTable.put`, so every retry fails the
same way until the kv config is corrected on the name server.
## Modification
`client/src/main/java/org/apache/rocketmq/client/impl/factory/MQClientInstance.java`:
in `topicRouteData2TopicPublishInfo`, validate each order topic conf segment —
skip segments without a `brokerName:queueNums` shape or with a non-numeric
queue count, with a warn log — instead of letting one malformed segment abort
the route conversion for the whole topic.
## Test Evidence
New test `testTopicRouteData2TopicPublishInfoWithMalformedOrderTopicConf` in
`MQClientInstanceTest` uses an order topic conf with two valid segments
(`broker-a:8`, `broker-d:2`) and two malformed ones (`broker-b` — no queue
count, `broker-c:eight` — non-numeric).
Fail-before (unpatched develop, new test only):
```
Tests run: 27, Failures: 0, Errors: 1, Skipped: 1
testTopicRouteData2TopicPublishInfoWithMalformedOrderTopicConf <<< ERROR!
java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
```
Pass-after (with fix, full class):
```
docker exec rmq-build mvn -pl client test -Dtest='MQClientInstanceTest'
-Dsurefire.failIfNoSpecifiedTests=true
Tests run: 30, Failures: 0, Errors: 0, Skipped: 0
```
The test asserts the malformed segments are skipped while the valid ones
still yield their queues (`broker-a` q0-q7, `broker-d` q0-q1, order topic flag
set).
No associated issue (self-discovered during a client-module self-audit).
--
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]