Commit fe904288 authored by Dave Cridland's avatar Dave Cridland

OF-889 Avoid NPE when session partially shutdown

Where ioSession.getRemoteAddress() returns null, this can cause an NPE.
parent e9aea579
...@@ -165,6 +165,7 @@ public class NIOConnection implements Connection { ...@@ -165,6 +165,7 @@ public class NIOConnection implements Connection {
public byte[] getAddress() throws UnknownHostException { public byte[] getAddress() throws UnknownHostException {
final SocketAddress remoteAddress = ioSession.getRemoteAddress(); final SocketAddress remoteAddress = ioSession.getRemoteAddress();
if (remoteAddress == null) throw new UnknownHostException();
final InetSocketAddress socketAddress = (InetSocketAddress) remoteAddress; final InetSocketAddress socketAddress = (InetSocketAddress) remoteAddress;
final InetAddress address = socketAddress.getAddress(); final InetAddress address = socketAddress.getAddress();
return address.getAddress(); return address.getAddress();
...@@ -172,6 +173,7 @@ public class NIOConnection implements Connection { ...@@ -172,6 +173,7 @@ public class NIOConnection implements Connection {
public String getHostAddress() throws UnknownHostException { public String getHostAddress() throws UnknownHostException {
final SocketAddress remoteAddress = ioSession.getRemoteAddress(); final SocketAddress remoteAddress = ioSession.getRemoteAddress();
if (remoteAddress == null) throw new UnknownHostException();
final InetSocketAddress socketAddress = (InetSocketAddress) remoteAddress; final InetSocketAddress socketAddress = (InetSocketAddress) remoteAddress;
final InetAddress inetAddress = socketAddress.getAddress(); final InetAddress inetAddress = socketAddress.getAddress();
return inetAddress.getHostAddress(); return inetAddress.getHostAddress();
...@@ -179,6 +181,7 @@ public class NIOConnection implements Connection { ...@@ -179,6 +181,7 @@ public class NIOConnection implements Connection {
public String getHostName() throws UnknownHostException { public String getHostName() throws UnknownHostException {
final SocketAddress remoteAddress = ioSession.getRemoteAddress(); final SocketAddress remoteAddress = ioSession.getRemoteAddress();
if (remoteAddress == null) throw new UnknownHostException();
final InetSocketAddress socketAddress = (InetSocketAddress) remoteAddress; final InetSocketAddress socketAddress = (InetSocketAddress) remoteAddress;
final InetAddress inetAddress = socketAddress.getAddress(); final InetAddress inetAddress = socketAddress.getAddress();
return inetAddress.getHostName(); return inetAddress.getHostName();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment