Fix NPE in NettyConnectionClient.toString (#13934)

This commit is contained in:
Albumen Kevin 2024-03-19 09:37:28 +08:00 committed by GitHub
parent c92e7ca72b
commit 392260a30e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 1 deletions

View File

@ -31,6 +31,7 @@ import org.apache.dubbo.remoting.transport.netty4.ssl.SslClientTlsHandler;
import org.apache.dubbo.remoting.transport.netty4.ssl.SslContexts;
import org.apache.dubbo.remoting.utils.UrlUtils;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
@ -337,7 +338,9 @@ public class NettyConnectionClient extends AbstractConnectionClient {
@Override
public String toString() {
return super.toString() + " (Ref=" + this.getCounter() + ",local="
+ (getChannel() == null ? null : getChannel().getLocalAddress()) + ",remote=" + getRemoteAddress();
+ Optional.ofNullable(getChannel())
.map(Channel::getLocalAddress)
.orElse(null) + ",remote=" + getRemoteAddress();
}
class ConnectionListener implements ChannelFutureListener {