Skip to content

Commit

Permalink
fix NPE when using advertisedListeners (apache#7620)
Browse files Browse the repository at this point in the history
### Modifications

Correct `BrokerServiceUrlTls` when `tls` is not enabled.
  • Loading branch information
murong00 authored Jul 28, 2020
1 parent 4f5b39a commit fcb0dc0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static Map<String, AdvertisedListener> validateAndAnalysisAdvertisedListe
throw new IllegalArgumentException("`advertisedListeners` and `advertisedAddress` must not appear together");
}
if (StringUtils.isBlank(config.getAdvertisedListeners())) {
return Collections.EMPTY_MAP;
return Collections.emptyMap();
}
Optional<String> firstListenerName = Optional.empty();
Map<String, List<String>> listeners = Maps.newHashMap();
Expand Down Expand Up @@ -101,11 +101,7 @@ public static Map<String, AdvertisedListener> validateAndAnalysisAdvertisedListe
}
String hostPort = String.format("%s:%d", uri.getHost(), uri.getPort());
reverseMappings.computeIfAbsent(hostPort, k -> Sets.newTreeSet());
Set<String> sets = reverseMappings.get(hostPort);
if (sets == null) {
sets = Sets.newTreeSet();
reverseMappings.put(hostPort, sets);
}
Set<String> sets = reverseMappings.computeIfAbsent(hostPort, k -> Sets.newTreeSet());
sets.add(entry.getKey());
if (sets.size() > 1) {
throw new IllegalArgumentException("must not specify `" + hostPort + "` to different listener.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,9 @@ private CompletableFuture<Optional<LookupResult>> findBrokerServiceUrl(Namespace
future.completeExceptionally(
new PulsarServerException("the broker do not have " + options.getAdvertisedListenerName() + " listener"));
} else {
URI urlTls = listener.getBrokerServiceUrlTls();
future.complete(Optional.of(new LookupResult(nsData.get(),
listener.getBrokerServiceUrl().toString(), listener.getBrokerServiceUrlTls().toString())));
listener.getBrokerServiceUrl().toString(), urlTls == null ? null : urlTls.toString())));
}
return;
} else {
Expand Down Expand Up @@ -471,8 +472,9 @@ private void searchForCandidateBroker(NamespaceBundle bundle,
new PulsarServerException("the broker do not have " + options.getAdvertisedListenerName() + " listener"));
return;
} else {
URI urlTls = listener.getBrokerServiceUrlTls();
lookupFuture.complete(Optional.of(new LookupResult(ownerInfo, listener.getBrokerServiceUrl().toString(),
listener.getBrokerServiceUrlTls().toString())));
urlTls == null ? null : urlTls.toString())));
return;
}
} else {
Expand Down

0 comments on commit fcb0dc0

Please sign in to comment.