Skip to content

Commit

Permalink
Fix NPE when address is null
Browse files Browse the repository at this point in the history
  • Loading branch information
oxsean committed Dec 2, 2024
1 parent 1ac934b commit 70b6ff6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ protected void doOpen() throws Throwable {
@Override
protected void initChannel(QuicChannel ch) {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(nettyServerHandler);
pipelineConfigurator.accept(pipeline);
pipeline.addLast(nettyServerHandler);
}
})
.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,38 +59,6 @@ public static InetSocketAddress getLocalAddress(Channel channel) {
return (InetSocketAddress) channel.localAddress();
}

public static String getRemoteAddressKey(Channel channel) {
InetSocketAddress address;
for (int i = 0, size = ACCESSORS.size(); i < size; i++) {
ChannelAddressAccessor accessor = ACCESSORS.get(i);
address = accessor.getRemoteAddress(channel);
if (address != null) {
return accessor.getProtocol() + ' ' + toAddressString(address);
}
}
InetSocketAddress remoteAddress = (InetSocketAddress) channel.remoteAddress();
if (remoteAddress == null) {
return "UNKNOWN";
}
return toAddressString(remoteAddress);
}

public static String getLocalAddressKey(Channel channel) {
InetSocketAddress address;
for (int i = 0, size = ACCESSORS.size(); i < size; i++) {
ChannelAddressAccessor accessor = ACCESSORS.get(i);
address = accessor.getLocalAddress(channel);
if (address != null) {
return accessor.getProtocol() + ' ' + toAddressString(address);
}
}
SocketAddress localAddress = channel.localAddress();
if (localAddress == null) {
return "UNKNOWN";
}
return toAddressString((InetSocketAddress) localAddress);
}

static void initAddressIfNecessary(NettyChannel nettyChannel) {
Channel channel = nettyChannel.getNioChannel();
SocketAddress address = channel.localAddress();
Expand Down Expand Up @@ -122,12 +90,18 @@ static InetSocketAddress getRemoteAddress(NettyChannel channel) {

static String getLocalAddressKey(NettyChannel channel) {
InetSocketAddress address = getLocalAddress(channel);
if (address == null) {
return "UNKNOWN";
}
String protocol = (String) channel.getAttribute(PROTOCOL_KEY);
return protocol == null ? toAddressString(address) : protocol + ' ' + toAddressString(address);
}

static String getRemoteAddressKey(NettyChannel channel) {
InetSocketAddress address = getRemoteAddress(channel);
if (address == null) {
return "UNKNOWN";
}
String protocol = (String) channel.getAttribute(PROTOCOL_KEY);
return protocol == null ? toAddressString(address) : protocol + ' ' + toAddressString(address);
}
Expand Down

0 comments on commit 70b6ff6

Please sign in to comment.