Add more constructors in ClosedChannelException

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


Link to Netty Issue:
1: https://github.com/netty/netty/pull/13099
[https://opengraph.githubassets.com/9dc9b173c70e1dfd7d5f80cb9ba16afedfd0579b06733a4eaf0ec8a562ce699e/netty/netty/pull/13099]<https://github.com/netty/netty/pull/13099>
Add `StacklessSSLHandshakeException` for `ClosedChannelException` by hyperxpro · Pull Request #13099 · netty/netty<https://github.com/netty/netty/pull/13099>
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...
github.com

________________________________
From: discuss <discuss-retn at openjdk.org> on behalf of Aayush Atharva <aayush at ShieldBlaze.com>
Sent: Tuesday, January 24, 2023 11:44 AM
To: discuss at openjdk.org <discuss at openjdk.org>
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
      at foo.bar(Meow.java:9999)
```

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.

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/discuss/attachments/20230124/2580bd95/attachment.htm>


More information about the discuss mailing list