INT-3843: Backport NPE Fix for TCP ConFactories

JIRA: https://jira.spring.io/browse/INT-3843

**Cherry-pick to the 3.0.x**
This commit is contained in:
Artem Bilan
2015-10-07 10:29:50 -04:00
committed by Gary Russell
parent ea394b44c0
commit b09cba64e0
2 changed files with 20 additions and 6 deletions

View File

@@ -87,7 +87,15 @@ public class TcpNetServerConnectionFactory extends AbstractServerConnectionFacto
* Not fatal.
*/
try {
socket = serverSocket.accept();
if (this.serverSocket == null) {
if (logger.isDebugEnabled()) {
logger.debug(this + " stopped before accept");
}
throw new IOException(this + " stopped before accept");
}
else {
socket = this.serverSocket.accept();
}
}
catch (SocketTimeoutException ste) {
if (logger.isDebugEnabled()) {

View File

@@ -95,11 +95,17 @@ public class TcpNioServerConnectionFactory extends AbstractServerConnectionFacto
this.serverChannel.socket().bind(new InetSocketAddress(whichNic, port), Math.abs(getBacklog()));
}
final Selector selector = Selector.open();
this.serverChannel.register(selector, SelectionKey.OP_ACCEPT);
setListening(true);
this.selector = selector;
doSelect(this.serverChannel, selector);
if (this.serverChannel == null) {
if (logger.isDebugEnabled()) {
logger.debug(this + " stopped before registering the server channel");
}
}
else {
this.serverChannel.register(selector, SelectionKey.OP_ACCEPT);
setListening(true);
this.selector = selector;
doSelect(this.serverChannel, selector);
}
}
catch (IOException e) {
if (isActive()) {