1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

Fix bug: NPE Exception.

https://github.com/apache/dubbo/issues/7079
This commit is contained in:
ganyu.gy 2021-01-07 16:00:30 +08:00
parent 573e8ed6c5
commit f64d794017

View File

@ -290,7 +290,7 @@ public class DubboCloudRegistry extends FailbackRegistry {
.map(templateURL -> templateURL.removeParameter(PID_KEY)) .map(templateURL -> templateURL.removeParameter(PID_KEY))
.map(templateURL -> { .map(templateURL -> {
String protocol = templateURL.getProtocol(); String protocol = templateURL.getProtocol();
int port = repository.getDubboProtocolPort(serviceInstance, Integer port = repository.getDubboProtocolPort(serviceInstance,
protocol); protocol);
if (Objects.equals(templateURL.getHost(), host) if (Objects.equals(templateURL.getHost(), host)
&& Objects.equals(templateURL.getPort(), port)) { // use && Objects.equals(templateURL.getPort(), port)) { // use
@ -300,6 +300,16 @@ public class DubboCloudRegistry extends FailbackRegistry {
return templateURL; return templateURL;
} }
if (port == null) {
if (logger.isWarnEnabled()) {
logger.warn(
"The protocol[{}] port of Dubbo service instance[host : {}] "
+ "can't be resolved",
protocol, host);
}
return null;
}
else {
URLBuilder clonedURLBuilder = from(templateURL) // remove the URLBuilder clonedURLBuilder = from(templateURL) // remove the
// parameters from // parameters from
// the template // the template
@ -308,7 +318,9 @@ public class DubboCloudRegistry extends FailbackRegistry {
.setPort(port); // reset the port .setPort(port); // reset the port
return clonedURLBuilder.build(); return clonedURLBuilder.build();
}).forEach(clonedExportedURLs::add); }
}).filter(Objects::nonNull).forEach(clonedExportedURLs::add);
}); });
return clonedExportedURLs; return clonedExportedURLs;
} }