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

Merge pull request #1903 from github-ganyu/master

Fix bug: NPE Exception.
This commit is contained in:
TheoneFx 2021-01-12 11:38:56 +08:00 committed by GitHub
commit dec10f17fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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,15 +300,27 @@ public class DubboCloudRegistry extends FailbackRegistry {
return templateURL; return templateURL;
} }
URLBuilder clonedURLBuilder = from(templateURL) // remove the if (port == null) {
// parameters from if (logger.isWarnEnabled()) {
// the template logger.warn(
// URL "The protocol[{}] port of Dubbo service instance[host : {}] "
.setHost(host) // reset the host + "can't be resolved",
.setPort(port); // reset the port protocol, host);
}
return null;
}
else {
URLBuilder clonedURLBuilder = from(templateURL) // remove the
// parameters from
// the template
// URL
.setHost(host) // reset the host
.setPort(port); // reset the port
return clonedURLBuilder.build(); return clonedURLBuilder.build();
}).forEach(clonedExportedURLs::add); }
}).filter(Objects::nonNull).forEach(clonedExportedURLs::add);
}); });
return clonedExportedURLs; return clonedExportedURLs;
} }