Add more constructors in ClosedChannelException

Aayush Atharva aayush at
Tue Jan 24 06:23:35 UTC 2023

Link to Netty Issue:
Add `StacklessSSLHandshakeException` for `ClosedChannelException` by hyperxpro · Pull Request #13099 · netty/netty<>
Motivation: When a channel is closed during the SSL handshake then java.nio.channels.ClosedChannelException is thrown. This is correct when we see it from a low-level transport perspective but from...

From: discuss <discuss-retn at> on behalf of Aayush Atharva <aayush at>
Sent: Tuesday, January 24, 2023 11:44 AM
To: discuss at <discuss at>
Subject: Add more constructors in ClosedChannelException

Hello JDK Community! 🙂

The current ClosedChannelException does not have any constructors to pass a message. We have to rely on 'initCause(...)'​ for passing extra messages regarding a ClosedChannelException but it's not a very good practice in my opinion. Because we will have to generate another Exception which will create another brand-new object in the heap and generates a stack trace. And all of this just to pass a simple message for ClosedChannelException.

When we log ClosedChannelException, we get something like this in our loggers:
java.nio.channels.ClosedChannelException: null

Honestly, it's not helpful at all. Netty[1] suffers from this same problem but we have added a new suppressed Stackless exception in ClosedChannelException which will help us give more context to users about the exception but this is really a workaround.

In my opinion, we can add extra constructors in ClosedChannelException which will accept messages and we can have a good exception at the end.

I'd like to have everyone's opinion on this and see how we can tackle this.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the discuss mailing list