nileshkumar3 opened a new pull request, #21609:
URL: https://github.com/apache/kafka/pull/21609
Summary
This PR hardens BuiltInPartitioner.partitionForKey(...) against invalid
partition counts.
partitionForKey previously performed % numPartitions directly, which could
throw ArithmeticException when numPartitions == 0.
This change adds explicit input validation and fails fast with a clearer
error.
Changes
1.
BuiltInPartitioner.partitionForKey(...) now validates numPartitions > 0.
2.
If invalid, it throws:
◦
IllegalArgumentException("numPartitions must be > 0, but was " +
numPartitions)
Tests
Added direct unit coverage in BuiltInPartitionerTest:
1.
testPartitionForKeyReturnsValidPartition
◦
Verifies returned partition is within [0, numPartitions).
2.
testPartitionForKeyThrowsIfNumPartitionsNotPositive
◦
Verifies IllegalArgumentException for numPartitions == 0 and -1.
Executed:
•
./gradlew :clients:test --tests
org.apache.kafka.clients.producer.internals.BuiltInPartitionerTest
All tests passed.
--
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]