Description
According to JAX-RS API 2.0 documentation the ContainerRequestContext.hasEntity() should return true only, when there is non-empty entity input stream available.
But ContainerRequestContextImpl always returns true for any non-GET request even if there is no entity passed with request - check ContainerRequestContextImpl.java:70:
@Override public boolean hasEntity() { InputStream is = getEntityStream(); return is != null && !HttpMethod.GET.equals(getMethod()); }
This happens due to the fact that getEntityStream() is never null. It always returns a DelegatingInputStream wrapper around javax.servlet.ServletInputStream put in message in AbstractHTTPDestination - check AbstractHTTPDestination.java:298:
DelegatingInputStream in = new DelegatingInputStream(req.getInputStream()) { ... // skipped }; inMessage.setContent(DelegatingInputStream.class, in); inMessage.setContent(InputStream.class, in);
Thus method contract is not satisfied. Presence of input stream doesn't mean that this stream has content. Implementation should check that there is indeed non-empty entity stream, e.g. via checking EOF using read() (obviously caching results for actual consumer).
N.B.: I believe the same issue affects ClientResponseContextImpl - check ClientResponseContextImpl.java:62:
@Override public boolean hasEntity() { return getEntityStream() != null; }