Open wilsongee opened 1 year ago
I believe the exception is thrown on purpose - at the time the stream is closed, the attempts for reading the entity are unexpected.
From the issue description, the use case for reading the entity when the stream is closed is not clear. In what situation do you read from the closed stream?
entityContent.isEmpty()
calls ensureNotClosed()
in its first line and is then caught when there is a possible IllegalStateException. That means the author of this code fragment intended to catch the IllegalStateException and return false.
It isn't because we're actively trying to read when the stream was closed by us. I believe there might be a race condition in our code somewhere and there could be a small chance, as evident by the handful of errors in our Splunk logging, that it could happen.
Relevant code:
It appears that we explicitly check to see if the stream is closed here: https://github.com/eclipse-ee4j/jersey/blob/2.x/core-common/src/main/java/org/glassfish/jersey/message/internal/InboundMessageContext.java#L814
It looks like we handle the exception and return false here: https://github.com/eclipse-ee4j/jersey/blob/2.x/core-common/src/main/java/org/glassfish/jersey/message/internal/InboundMessageContext.java#L820
Stacktrace with personal lines scrubbed out:
In this particular case, I think it makes sense to move the
entityContent.ensureNotClosed();
statement into the try block below it.To work around this issue, I have to handle my invocation of hasEntity() myself outside of an if-statement for legibility sake.
Sample work around: