gaoxiaolei-s59 opened a new issue, #10458:
URL: https://github.com/apache/rocketmq/issues/10458

   ### Before Creating the Bug Report
   
   - [x] I have searched the existing issues and pull requests.
   
   ### Runtime platform environment
   
   Any Java runtime using `MessageBatch.generateFromList`.
   
   ### RocketMQ version
   
   Current `develop` branch.
   
   ### Describe the Bug
   
   `MessageBatch.generateFromList(Collection<? extends Message> messages)` 
currently validates `messages != null` and `messages.size() > 0` with Java 
`assert` statements. This makes invalid input handling depend on whether 
assertions are enabled.
   
   When assertions are enabled, null or empty input throws `AssertionError`. 
When assertions are disabled, the same invalid input can continue and fail 
later with `NullPointerException` while dereferencing the first message.
   
   For a public batch-construction helper used by producer batch send paths, 
null or empty input should be rejected consistently with an explicit argument 
exception.
   
   ### Steps to Reproduce
   
   1. Call `MessageBatch.generateFromList(null)`, or call it with an empty 
collection.
   2. Observe that the thrown error depends on the assertion setting instead of 
a stable parameter validation exception.
   
   ### What Did You Expect to See?
   
   The method should consistently reject null or empty input with 
`IllegalArgumentException`.
   
   ### What Did You See Instead?
   
   The method relies on Java assertions. This can produce `AssertionError` with 
assertions enabled, or later `NullPointerException` with assertions disabled.
   
   ### Additional Context
   
   A small unit test can cover both invalid inputs in `MessageBatchTest`.
   


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