Environment
- Dubbo version: 3.0
- Operating System version: Any
- Java version: 1.8
Steps to reproduce this issue
An NPE could be thrown at line 124 of org.apache.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance. selectedWRR could be null because the condition cur > maxCurrent may not be true.
protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation invocation) {
WeightedRoundRobin selectedWRR = null;
// other codes
for (Invoker<T> invoker : invokers) {
// other codes
if (cur > maxCurrent) {
selectedWRR = weightedRoundRobin;
}
}
if (selectedInvoker != null) {
selectedWRR.sel(totalWeight); // selectedWRR could be null.
return selectedInvoker;
}
Actual Behavior
An NPE could be thrown at line 124 because no defensive null check is provided.