This is an automated email from the ASF dual-hosted git repository. rxl pushed a commit to branch branch-2.6 in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 53ee16dce2ef5e5011ef1e676be4eba635d8706e Author: Fangbin Sun <sunfang...@gmail.com> AuthorDate: Tue Jul 28 16:17:24 2020 +0800 fix NPE when using advertisedListeners (#7620) ### Modifications Correct `BrokerServiceUrlTls` when `tls` is not enabled. (cherry picked from commit fcb0dc04b3262249c1a8f7e7964ff8f0487f0acc) --- .../apache/pulsar/broker/validator/MultipleListenerValidator.java | 8 ++------ .../java/org/apache/pulsar/broker/namespace/NamespaceService.java | 6 ++++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/validator/MultipleListenerValidator.java b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/validator/MultipleListenerValidator.java index 9f44da8..f97f4aa 100644 --- a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/validator/MultipleListenerValidator.java +++ b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/validator/MultipleListenerValidator.java @@ -52,7 +52,7 @@ public final class MultipleListenerValidator { 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(); @@ -101,11 +101,7 @@ public final class MultipleListenerValidator { } 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."); diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java index 0fa4957..b50e769 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java @@ -395,8 +395,9 @@ public class NamespaceService { future.completeExceptionally( new PulsarServerException("the broker do not have " + advertisedListenerName + " 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 { @@ -496,8 +497,9 @@ public class NamespaceService { new PulsarServerException("the broker do not have " + advertisedListenerName + " 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 {