Skip to content

Commit 5cdcd81

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 544de6b commit 5cdcd81

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

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

Lines changed: 5 additions & 7 deletions
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
*/
@@ -181,12 +183,7 @@ public void run() {
181183
else if (isActive()) {
182184
logger.error("Error on ServerSocket; port = " + getPort(), e);
183185
publishServerExceptionEvent(e);
184-
try {
185-
this.serverSocket.close();
186-
}
187-
catch (IOException e1) {
188-
// empty
189-
}
186+
stop();
190187
}
191188
}
192189
finally {
@@ -223,7 +220,8 @@ public void stop() {
223220
try {
224221
this.serverSocket.close();
225222
}
226-
catch (IOException e) { }
223+
catch (IOException e) {
224+
}
227225
this.serverSocket = null;
228226
super.stop();
229227
}

0 commit comments

Comments
 (0)