async-http-client
async-http-client copied to clipboard
Make RemotelyClosedException Read Only or Throw New
Can the RemotelyClosedException be made read only, or can a new one be thrown every time? The issue is that the exception is basically static, but is maniplulatable, allowing the cause to be altered, suppressed exceptions to be added, and the stack trace modified, which has a fake stack trace to start with. This goes for other similar exceptions like ChannelClosedException. At the very least, user code should be prevented from modifying it.
Just out of curiosity, why is a new exception not thrown?
At the very least, user code should be prevented from modifying it.
Contributions welcome.
Just out of curiosity, why is a new exception not thrown?
RemotelyClosedException is used for flow control for retry. We don't want to copy native stacktrace for this. Netty does that a lot too. And we reduce stacktrace because those exceptions are thrown from one single point in the code and we don't want to flood logging once they are thrown.
Can we make them unmodifiable then, using the special constructor that prevents stack trace modification and suppressed exceptions.
Can we make them unmodifiable then, using the special constructor that prevents stack trace modification and suppressed exceptions.
Hardly, this constructor is on Throwable so we can't extend IOException.
I don't think what you'd like to do is feasible without losing the one level stacktrace we currently have in ThrowableUtil#unknownStackTrace.
FYI, we do the exact same thing as Netty: https://github.com/netty/netty/blob/4.1/common/src/main/java/io/netty/util/internal/ThrowableUtil.java#L30-L33.
Okay. Will figure out which exceptions these are and prevent their modification another way.
The issue can be closed.