Closed shenluw closed 3 years ago
I have not reproduced your problem here. Can you provide a demo to reproduce this problem?
你可以参考这个demo
What version of nacos-server are you using?
What version of nacos-server are you using?
nacos server 1.1.4
Ok, I find out the reasion, I will fix it.
It's the lower version nacos server problem, the the config is not found, nacos server 1.1.4 will return null response. In dubbo, will do some operation for the response. So the npe occur. At nacos high version, it will return empty data response when the data is not found, so it won't cause npe. We should do compatible work for low nacos server.
Environment
Steps to reproduce this issue
注册中心使用nacos 1.1.4
依赖如下
`
`
dubbo配置如下
dubbo: registry: address: nacos://xxxxx:8848
消费者使用泛化调用目标接口会出现npe 但是不影响调用结果,
代码如下 ` ReferenceConfig reference = new ReferenceConfig<>();
reference.setGeneric(true);
reference.setApplication(applicationConfig);
reference.setRegistry(registryConfig);
reference.setInterface(metaData.getServiceName());
reference.setProtocol("dubbo");
try {
Object obj = reference.get();
if (obj != null) {
log.info("init alibaba dubbo reference success there meteData is :{}", metaData.toString());
cache.put(metaData.getServiceName(), reference);
}
} catch (Exception e) {
log.error("init alibaba dubbo refernce ex", e);
}
`
Actual Result
泛化调用初始化时总是会出现npe,原因是什么? 缺少配置吗?
java.lang.NullPointerException: null at org.apache.dubbo.configcenter.support.nacos.NacosDynamicConfiguration.toKeysStream(NacosDynamicConfiguration.java:287) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.configcenter.support.nacos.NacosDynamicConfiguration.getConfigKeys(NacosDynamicConfiguration.java:262) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.common.config.configcenter.wrapper.CompositeDynamicConfiguration.lambda$getConfigKeys$5(CompositeDynamicConfiguration.java:82) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.common.config.configcenter.wrapper.CompositeDynamicConfiguration.iterateConfigOperation(CompositeDynamicConfiguration.java:94) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.common.config.configcenter.wrapper.CompositeDynamicConfiguration.getConfigKeys(CompositeDynamicConfiguration.java:82) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.metadata.DynamicConfigurationServiceNameMapping.lambda$getAndListen$1(DynamicConfigurationServiceNameMapping.java:80) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.metadata.DynamicConfigurationServiceNameMapping.execute(DynamicConfigurationServiceNameMapping.java:90) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.metadata.DynamicConfigurationServiceNameMapping.getAndListen(DynamicConfigurationServiceNameMapping.java:78) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.registry.client.ServiceDiscoveryRegistry.findMappedServices(ServiceDiscoveryRegistry.java:417) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.registry.client.ServiceDiscoveryRegistry.getServices(ServiceDiscoveryRegistry.java:382) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.registry.client.ServiceDiscoveryRegistry.doSubscribe(ServiceDiscoveryRegistry.java:262) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.registry.client.ServiceDiscoveryRegistry.subscribe(ServiceDiscoveryRegistry.java:256) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.registry.ListenerRegistryWrapper.subscribe(ListenerRegistryWrapper.java:105) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.registry.integration.DynamicDirectory.subscribe(DynamicDirectory.java:154) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.registry.integration.RegistryProtocol.doCreateInvoker(RegistryProtocol.java:525) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.registry.integration.InterfaceCompatibleRegistryProtocol.getServiceDiscoveryInvoker(InterfaceCompatibleRegistryProtocol.java:77) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.registry.client.migration.MigrationInvoker.refreshServiceDiscoveryInvoker(MigrationInvoker.java:295) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.registry.client.migration.MigrationInvoker.migrateToServiceDiscoveryInvoker(MigrationInvoker.java:112) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.registry.client.migration.MigrationRuleHandler.doMigrate(MigrationRuleHandler.java:58) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.registry.client.migration.MigrationRuleListener.onRefer(MigrationRuleListener.java:103) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.registry.integration.RegistryProtocol.interceptInvoker(RegistryProtocol.java:498) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.registry.integration.RegistryProtocol.doRefer(RegistryProtocol.java:483) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.registry.integration.RegistryProtocol.refer(RegistryProtocol.java:477) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.rpc.protocol.ProtocolListenerWrapper.refer(ProtocolListenerWrapper.java:72) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper.refer(ProtocolFilterWrapper.java:81) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.qos.protocol.QosProtocolWrapper.refer(QosProtocolWrapper.java:73) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.rpc.Protocol$Adaptive.refer(Protocol$Adaptive.java) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:378) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:313) ~[dubbo-2.7.12.jar:2.7.12] at org.apache.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:206) ~[dubbo-2.7.12.jar:2.7.12]