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 b35779acc6..15a265a09f 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 @@ -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()) { 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 a4069c96a1..aac064ad64 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 @@ -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()) {