You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "dajac (via GitHub)" <gi...@apache.org> on 2026/04/25 14:07:55 UTC
[PR] MINOR: Reshape TxnOffsetCommitResponse.Builder [kafka]
dajac opened a new pull request, #22146:
URL: https://github.com/apache/kafka/pull/22146
This patch refactors `TxnOffsetCommitResponse.Builder` to mirror the
class hierarchy used by `OffsetCommitResponse.Builder`: the `Builder`
becomes abstract and the existing topic-name-keyed logic moves to a
`TopicNameBuilder` subclass. A new `newBuilder()` factory replaces
the only direct `new Builder()` call site in `KafkaApis`. Unit tests
covering `addPartition`, `addPartitions`, `merge`, and the
null-name guard are added in `TxnOffsetCommitResponseTest`.
The change is behavior-preserving. It prepares the ground for a
future `TopicIdBuilder` subclass that will be added when
`TxnOffsetCommit` gains topic ID support.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: Reshape TxnOffsetCommitResponse.Builder [kafka]
Posted by "dajac (via GitHub)" <gi...@apache.org>.
dajac merged PR #22146:
URL: https://github.com/apache/kafka/pull/22146
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: Reshape TxnOffsetCommitResponse.Builder [kafka]
Posted by "dajac (via GitHub)" <gi...@apache.org>.
dajac commented on code in PR #22146:
URL: https://github.com/apache/kafka/pull/22146#discussion_r3155505588
##########
clients/src/main/java/org/apache/kafka/common/requests/TxnOffsetCommitResponse.java:
##########
@@ -127,6 +124,41 @@ public TxnOffsetCommitResponse build() {
}
}
+ public static class TopicNameBuilder extends Builder {
+ private final HashMap<String, TxnOffsetCommitResponseTopic> byTopicName = new HashMap<>();
+
+ @Override
+ protected void add(TxnOffsetCommitResponseTopic topic) {
+ throwIfTopicNameIsNull(topic.name());
+ data.topics().add(topic);
+ byTopicName.put(topic.name(), topic);
+ }
+
+ @Override
+ protected TxnOffsetCommitResponseTopic get(String topicName) {
+ throwIfTopicNameIsNull(topicName);
+ return byTopicName.get(topicName);
+ }
+
+ @Override
+ protected TxnOffsetCommitResponseTopic getOrCreate(String topicName) {
+ throwIfTopicNameIsNull(topicName);
+ TxnOffsetCommitResponseTopic topic = byTopicName.get(topicName);
+ if (topic == null) {
+ topic = new TxnOffsetCommitResponseTopic().setName(topicName);
+ data.topics().add(topic);
+ byTopicName.put(topicName, topic);
+ }
+ return topic;
+ }
+
+ private static void throwIfTopicNameIsNull(String topicName) {
+ if (topicName == null) {
Review Comment:
It is basically `IllegalArgumentException` vs `NullPointerException`.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: Reshape TxnOffsetCommitResponse.Builder [kafka]
Posted by "dajac (via GitHub)" <gi...@apache.org>.
dajac commented on PR #22146:
URL: https://github.com/apache/kafka/pull/22146#issuecomment-4319789288
@squah-confluent Could you please review when you get a chance?
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: Reshape TxnOffsetCommitResponse.Builder [kafka]
Posted by "AndrewJSchofield (via GitHub)" <gi...@apache.org>.
AndrewJSchofield commented on code in PR #22146:
URL: https://github.com/apache/kafka/pull/22146#discussion_r3154236879
##########
clients/src/main/java/org/apache/kafka/common/requests/TxnOffsetCommitResponse.java:
##########
@@ -127,6 +124,41 @@ public TxnOffsetCommitResponse build() {
}
}
+ public static class TopicNameBuilder extends Builder {
+ private final HashMap<String, TxnOffsetCommitResponseTopic> byTopicName = new HashMap<>();
+
+ @Override
+ protected void add(TxnOffsetCommitResponseTopic topic) {
+ throwIfTopicNameIsNull(topic.name());
+ data.topics().add(topic);
+ byTopicName.put(topic.name(), topic);
+ }
+
+ @Override
+ protected TxnOffsetCommitResponseTopic get(String topicName) {
+ throwIfTopicNameIsNull(topicName);
+ return byTopicName.get(topicName);
+ }
+
+ @Override
+ protected TxnOffsetCommitResponseTopic getOrCreate(String topicName) {
+ throwIfTopicNameIsNull(topicName);
+ TxnOffsetCommitResponseTopic topic = byTopicName.get(topicName);
+ if (topic == null) {
+ topic = new TxnOffsetCommitResponseTopic().setName(topicName);
+ data.topics().add(topic);
+ byTopicName.put(topicName, topic);
+ }
+ return topic;
+ }
+
+ private static void throwIfTopicNameIsNull(String topicName) {
+ if (topicName == null) {
Review Comment:
Any reason why you're not using `Objects.requireNonNull`?
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org