Skip to content

Commit

Permalink
Fix NPE in the TcpNetServerConnectionFactory
Browse files Browse the repository at this point in the history
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**
  • Loading branch information
artembilan authored and garyrussell committed Apr 2, 2018
1 parent 04a61f1 commit de9aeac
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
* a {@link ServerSocket}. Must have a {@link TcpListener} registered.
*
* @author Gary Russell
* @author Artem Bilan
*
* @since 2.0
*
*/
Expand Down Expand Up @@ -181,12 +183,7 @@ public void run() {
else if (isActive()) {
logger.error("Error on ServerSocket; port = " + getPort(), e);
publishServerExceptionEvent(e);
try {
this.serverSocket.close();
}
catch (IOException e1) {
// empty
}
stop();
}
}
finally {
Expand Down Expand Up @@ -223,7 +220,8 @@ public void stop() {
try {
this.serverSocket.close();
}
catch (IOException e) { }
catch (IOException e) {
}
this.serverSocket = null;
super.stop();
}
Expand Down

0 comments on commit de9aeac

Please sign in to comment.