Add more constructors in ClosedChannelException

Aayush Atharva aayush at ShieldBlaze.com
Tue Jan 24 06:14:28 UTC 2023


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/839ac40a/attachment-0001.htm>


More information about the discuss mailing list