Skip to content

Commit

Permalink
spring-projectsGH-9694: Add null check when closing SocketChannel
Browse files Browse the repository at this point in the history
Fixes: spring-projects#9694
Issue link: spring-projects#9694

- Add null check before closing socketChannel in catch block
- Prevents potential NullPointerException during error handling
  • Loading branch information
anthologia committed Dec 6, 2024
1 parent 4c8d27f commit 6efba1d
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,11 @@ protected TcpConnectionSupport buildNewConnection() {
}
catch (IOException e) {
try {
socketChannel.close();
} catch (IOException e2) {
if (socketChannel != null) {
socketChannel.close();
}
}
catch (IOException e2) {
logger.error(e2, "Error closing socket channel");
}
throw new UncheckedIOException(e);
Expand Down

0 comments on commit 6efba1d

Please sign in to comment.