C0urante commented on code in PR #16767:
URL: https://github.com/apache/kafka/pull/16767#discussion_r1705660480
##########
connect/mirror/src/main/java/org/apache/kafka/connect/mirror/MirrorCheckpointConnector.java:
##########
@@ -133,6 +132,13 @@ public Class<? extends Task> taskClass() {
// divide consumer groups among tasks
@Override
public List<Map<String, String>> taskConfigs(int maxTasks) {
+ if (Objects.isNull(knownConsumerGroups)) {
Review Comment:
Can we just use `== null`? `Objects::isNull` was introduced in Java 8 to
make streams operations and other lambda/method reference-based APIs easier to
work with.
See the
[Javadocs](https://docs.oracle.com/javase/8/docs/api/java/util/Objects.html#isNull-java.lang.Object-):
> API Note:
This method exists to be used as a
[Predicate](https://docs.oracle.com/javase/8/docs/api/java/util/function/Predicate.html),
`filter(Objects::isNull)`
##########
connect/mirror/src/main/java/org/apache/kafka/connect/mirror/MirrorCheckpointConnector.java:
##########
@@ -186,6 +192,8 @@ public boolean alterOffsets(Map<String, String>
connectorConfig, Map<Map<String,
private void refreshConsumerGroups()
throws InterruptedException, ExecutionException {
+ // Checking null to avoid NPE.
+ Set<String> knownConsumerGroups =
Objects.isNull(this.knownConsumerGroups) ? Collections.emptySet() :
this.knownConsumerGroups;
Review Comment:
1. Same nit RE `Objects::isNull`; we can probably do something like this
instead: `this.knownConsumerGroups != null ? this.knownConsumerGroups :
Collections.emptySet()`
2. I agree that it's good to safeguard against NPEs, but maybe we can
elaborate in the comment why this is necessary: if `loadInitialConsumerGroups`
fails for some reason, then `knownConsumerGroups` may be null, and we still
want this method to be able to recover gracefully.
--
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]