eclipse-ee4j / eclipse-ee4j/jersey
Broken exception handling in org.glassfish.jersey.servlet.WebComponent#initContainerRequest since 2.44 (also in 3.1.9)
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
@jansupol , with https://github.com/eclipse-ee4j/jersey/commit/d8f3e0fba99262feffed245f5b22d1836da7ea10#diff-937cc5e5415a0412aa6850cc416fffb46747e443997e2d50b69162ba3af82b5c (https://github.com/eclipse-ee4j/jersey/pull/5669) you implemented an exception handling, that is not working as intended. This was a fix for https://github.com/eclipse-ee4j/jersey/issues/4867 . Let me first walk you through the issue.
You updated org.glassfish.jersey.servlet.WebComponent#initContainerRequest from (2.43):
```
requestContext.setEntityStream(servletRequest.getInputStream());
```
to (2.44):
```
try {
requestContext.setEntityStream(new InputStreamWrapper() {
@Override
protected InputStream getWrapped() {
try {
return servletRequest.getInputStream();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
});
} catch (UncheckedIOException e) {
throw e.getCause();
}
```
In case of an `IOException` on calling `getInputStream` `initContainerRequest` failed right away with the same `IOException` in 2.43.
After this change the `getInputStream` is not called at all in `initContainerRequest` and everything is fine for now.
Nevertheless, at the first call on the EntityStream e.g.: `requestContext.getEntityStream().available()` the call will fail with your `UncheckedIOException`. But at this point in time we long left the try-catch-block and the `UncheckedIOException` is being propagated through the system.
Please check https://github.com/mheinzerling/jersey/commit/1473d8d9ba88c80513b91c3f9077b2fcac8293c6 for a simple test demonstrating the old behavior.
And https://github.com/mheinzerling/jersey/commit/7a677ee86f5b5d85e75cb12a2b6bbe127ab930b1 is showing the new behavior.
In both cases I just extracted a static method to reduce the test setup and the `mock*Request` methods are also identical.
As mentioned above, I don't know what you tried to achieve with this change, so I can't recommend a fix. But at least in our system, I didn't notice any issue in just rolling back this snippet.
The same issue exists in 3.1.9.
Related to https://github.com/eclipse-ee4j/jersey/issues/5739
Please don't hesitate to send me a message if there are further questions. Thanks.
Contributor guide
Assessment
This issue has not been assessed yet.