Open slankka opened 1 month ago
经过Debug 构造函数这里接收了空值,难以复现,但2024年了,还是遇到了
@Override
public Registry getRegistry(URL url) {
return new RegistryWrapper(registryFactory.getRegistry(url)); // registryFactory.getRegistry = null
}
class RegistryWrapper implements Registry {
private Registry originRegistry;
public RegistryWrapper(Registry originRegistry) {
this.originRegistry = originRegistry;
}
......
@Override
public void register(URL url) {
originRegistry.register(appendProviderAppName(url)); //NPE : originRegistry = null
}
临时修复建议
@Override
public Registry getRegistry(URL url) {
Registry registry = registryFactory.getRegistry(url);
if (registry == null) {
logger.info("registry is null url " + url);
return registry;
}
return new RegistryWrapper(registry);
}
依据:可以看到 Dubbo 的 ListenerRegistryWrapper 进行了registry != null 判断,并且从该PR开始,getRegistry根据check进行判断,check=false的时候,registry是可以等于null的
https://github.com/apache/dubbo/pull/8483
public class ListenerRegistryWrapper implements Registry {
@Override
public void register(URL url) {
try {
if (registry != null) {
registry.register(url);
}
} finally {
if (!UrlUtils.isConsumer(url)) {
listenerEvent(serviceListener -> serviceListener.onRegister(url, registry));
}
}
}
}
依据2:
public abstract class AbstractRegistryFactory implements RegistryFactory {
......
if (check && registry == null) {
throw new IllegalStateException("Can not create registry " + url);
}
if (registry != null) {
REGISTRIES.put(key, registry);
}
return registry;
}
}
Describe the bug CatRegistryFactoryWrapper has a potential NPE bug
To Reproduce
Expected behavior normal startup
Versions Dubbo 3.1.6 Spring 5.2.8.RELEASE
Exception