Commit 46e87630 authored by Dave Cridland's avatar Dave Cridland

OF-889 Catch and handle NPEs while getting addresses etc

Where the session is part-closed, these can throw NPE due to getRemoteAddress()
returning null. This sledge-hammers the problem away.
parent 9e409e60
......@@ -162,15 +162,27 @@ public class NIOConnection implements Connection {
}
public byte[] getAddress() throws UnknownHostException {
return ((InetSocketAddress) ioSession.getRemoteAddress()).getAddress().getAddress();
try {
return ((InetSocketAddress) ioSession.getRemoteAddress()).getAddress().getAddress();
} catch (NullPointerException e) {
throw new UnknownHostException();
}
}
public String getHostAddress() throws UnknownHostException {
return ((InetSocketAddress) ioSession.getRemoteAddress()).getAddress().getHostAddress();
try {
return ((InetSocketAddress) ioSession.getRemoteAddress()).getAddress().getHostAddress();
} catch (NullPointerException e) {
throw new UnknownHostException();
}
}
public String getHostName() throws UnknownHostException {
return ((InetSocketAddress) ioSession.getRemoteAddress()).getAddress().getHostName();
try {
return ((InetSocketAddress) ioSession.getRemoteAddress()).getAddress().getHostName();
} catch (NullPointerException e) {
throw new UnknownHostException();
}
}
public Certificate[] getLocalCertificates() {
......
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