diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetServerConnectionFactory.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetServerConnectionFactory.java index 0504f2f693..17da270f05 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetServerConnectionFactory.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetServerConnectionFactory.java @@ -80,7 +80,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()) { diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioServerConnectionFactory.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioServerConnectionFactory.java index 782df53890..6ddf419c20 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioServerConnectionFactory.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioServerConnectionFactory.java @@ -92,11 +92,17 @@ public class TcpNioServerConnectionFactory extends AbstractServerConnectionFacto Math.abs(this.getBacklog())); } final Selector selector = Selector.open(); - this.serverChannel.register(selector, SelectionKey.OP_ACCEPT); - this.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) { this.close();