apache / dubbo

The java implementation of Apache Dubbo. An RPC and microservice framework.
https://dubbo.apache.org/
Apache License 2.0
40.5k stars 26.43k forks source link

dubbo 2.7.12 使用泛化调用初始化总是出现NPE #8181

Closed shenluw closed 3 years ago

shenluw commented 3 years ago

Environment

Steps to reproduce this issue

注册中心使用nacos 1.1.4

依赖如下

`

com.alibaba.boot nacos-config-spring-boot-starter 0.2.8
  <dependency>
    <groupId>org.apache.dubbo</groupId>
    <artifactId>dubbo-spring-boot-starter</artifactId>
    <version>2.7.12</version>
  </dependency>

`

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]

xiaoheng1 commented 3 years ago

I have not reproduced your problem here. Can you provide a demo to reproduce this problem?

shenluw commented 3 years ago

你可以参考这个demo

https://github.com/shenluw/dubbo-generic-demo

xiaoheng1 commented 3 years ago

What version of nacos-server are you using?

shenluw commented 3 years ago

What version of nacos-server are you using?

nacos server 1.1.4

horizonzy commented 3 years ago

Ok, I find out the reasion, I will fix it.

horizonzy commented 3 years ago

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.