Skip to content

Commit 477c071

Browse files
artembilangaryrussell
authored andcommitted
Fix NPE in the TcpNetServerConnectionFactory
https://build.spring.io/browse/INTSAMPLES-NIGHTLY-2413 When we fail with the `java.net.BindException: Address already in use (Bind failed)` in the `TcpNetServerConnectionFactory.run()`, the `serverSocket` property remains `null` and we get `NPE` in the `catch` block trying to `close()` the socket. * Call `stop()` instead which has all the required protections. **Cherry-pick to 5.0.x and 4.3.x**
1 parent a6771bc commit 477c071

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetServerConnectionFactory.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
* a {@link ServerSocket}. Must have a {@link TcpListener} registered.
3434
*
3535
* @author Gary Russell
36+
* @author Artem Bilan
37+
*
3638
* @since 2.0
3739
*
3840
*/
@@ -155,6 +157,7 @@ public void run() {
155157
else if (isActive()) {
156158
logger.error("Error on ServerSocket; port = " + getPort(), e);
157159
publishServerExceptionEvent(e);
160+
stop();
158161
}
159162
}
160163
finally {
@@ -191,7 +194,8 @@ public void stop() {
191194
try {
192195
this.serverSocket.close();
193196
}
194-
catch (IOException e) { }
197+
catch (IOException e) {
198+
}
195199
this.serverSocket = null;
196200
super.stop();
197201
}

0 commit comments

Comments
 (0)