NacosClientRegisterRepository#persistInterface occurs NPE when the value of port is null
Describe the bug
NacosClientRegisterRepository#persistInterface occurs NPE when the value of port is null ,so Integer auto-unboxing occurs NPE. I found that in ContextRegisterListener#buildMetaDataDTO method missing the parameter of port.
Environment
- Soul version(s): 2.3.0-RELEASE
Steps to reproduce
Exception in thread "soul-disruptor-soul_disruptor_consumer_-17" java.lang.NullPointerException at org.dromara.soul.register.client.nacos.NacosClientRegisterRepository.persistInterface(NacosClientRegisterRepository.java:84) at org.dromara.soul.client.core.disruptor.subcriber.SoulClientMetadataExecutorSubscriber.executor(SoulClientMetadataExecutorSubscriber.java:53) at org.dromara.soul.client.core.disruptor.executor.RegisterClientConsumerExecutor.run(RegisterClientConsumerExecutor.java:43) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)
Expected behavior
Debug logs
Click to expand
replace this line with your debug logs
hi, please show you config ..
config Hi,follow figure is my configuration
btw,the ContextRegisterListener#buildMetaDataDTO method missed the port parameter ,so i think this may be a bug. private MetaDataRegisterDTO buildMetaDataDTO() { String contextPath = this.contextPath; String appName = env.getProperty("spring.application.name"); String path = contextPath + "/**"; return MetaDataRegisterDTO.builder() .contextPath(contextPath) .appName(appName) .path(path) .rpcType(RpcTypeEnum.SPRING_CLOUD.getName()) .enabled(true) .ruleName(path) .build(); }
thanks,we will see it.
what rpc you used? you dependency soul-client-xxxxx?
dependency rpc type is spring cloud,the dependency is
org.dromara soul-register-client-nacos org.dromara soul-spring-boot-starter-client-springcloud
in master? have problem?
The problem still exist in master branch when 'soul.client.props.isFull' is equls true in configuration file . Is the value of port optional or can be null when register the meta into nacos , If not i think in method buildMetaDataDTO() should set the port value like this: private MetaDataRegisterDTO buildMetaDataDTO() { String contextPath = this.contextPath; String appName = env.getProperty("spring.application.name"); Integer port = env.getProperty("server.port",Integer.class,8080); String path = contextPath + "/**"; return MetaDataRegisterDTO.builder() .contextPath(contextPath) .appName(appName) .path(path) .rpcType(RpcTypeEnum.SPRING_CLOUD.getName()) .enabled(true) .ruleName(path) .port(port) .build(); }
What is you all config? please show the all config. Because .ocal cannot be reproduced.
give config like this:
server:
port:
address: 0.0.0.0
spring:
application:
name: springCloud-test
# cloud:
# nacos:
# discovery:
# server-addr: 127.0.0.1:8848
springCloud-test:
ribbon.NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
instance:
prefer-ip-address: true
soul:
client:
registerType: nacos #http #zookeeper #etcd #nacos #consul
serverLists: localhost:8848 #http://localhost:9095 #localhost:2181 #http://localhost:2379 #localhost:8848
props:
contextPath: /springcloud
port: ${server.port}
nacosNameSpace: SoulRegisterCenter
logging:
level:
root: info
org.dromara.soul: debug
btw,the ContextRegisterListener#buildMetaDataDTO method missed the port parameter ,so i think this may be a bug.
private MetaDataRegisterDTO buildMetaDataDTO() {
String contextPath = this.contextPath;
String appName = env.getProperty("spring.application.name");
String path = contextPath + "/**";
return MetaDataRegisterDTO.builder()
.contextPath(contextPath)
.appName(appName)
.path(path)
.rpcType(RpcTypeEnum.SPRING_CLOUD.getName())
.enabled(true)
.ruleName(path)
.build();
}