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

Polish spring-cloud-incubator/spring-cloud-alibaba#556 : NPE should be avoid When ServiceRestMetadata can't be found

This commit is contained in:
mercyblitz 2019-04-15 22:14:07 +08:00
parent 431dfddb4e
commit b17d6bf945

View File

@ -37,6 +37,7 @@ import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.http.HttpRequest; import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import java.util.Collection; import java.util.Collection;
@ -260,8 +261,10 @@ public class DubboServiceMetadataRepository {
Set<ServiceRestMetadata> metadata = Collections.emptySet(); Set<ServiceRestMetadata> metadata = Collections.emptySet();
try { try {
String serviceRestMetadataJsonConfig = dubboMetadataService.getServiceRestMetadata(); String serviceRestMetadataJsonConfig = dubboMetadataService.getServiceRestMetadata();
metadata = objectMapper.readValue(serviceRestMetadataJsonConfig, if(StringUtils.hasText(serviceRestMetadataJsonConfig)) {
TypeFactory.defaultInstance().constructCollectionType(LinkedHashSet.class, ServiceRestMetadata.class)); metadata = objectMapper.readValue(serviceRestMetadataJsonConfig,
TypeFactory.defaultInstance().constructCollectionType(LinkedHashSet.class, ServiceRestMetadata.class));
}
} catch (Exception e) { } catch (Exception e) {
if (logger.isErrorEnabled()) { if (logger.isErrorEnabled()) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);