Details
-
Type:
Bug
-
Status: Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 3.0.1
-
Component/s: JAX-RS
-
Labels:None
-
Environment:
Ubuntu 14.04.1 LTS, x86_64.
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
-
Estimated Complexity:Unknown
Description
This small test:
@Test public void should_read_entity() { final String str = "ouch"; Response response = Response.status(Response.Status.INTERNAL_SERVER_ERROR) .entity(str) .build(); Assert.assertEquals(str, response.readEntity(String.class)); }
unexpectedly throws `NullPointerException` with the following stacktrace:
at org.apache.cxf.jaxrs.provider.ProviderFactory.getInstance(ProviderFactory.java:950) at org.apache.cxf.jaxrs.impl.ResponseImpl.doReadEntity(ResponseImpl.java:357) at org.apache.cxf.jaxrs.impl.ResponseImpl.readEntity(ResponseImpl.java:319) at org.apache.cxf.jaxrs.impl.ResponseImpl.readEntity(ResponseImpl.java:309)
(because Response created by Response.build() has outMessage == null).
JAX-RS specifies that Response.readEntity() throws only ProcessingException and IllegalStateException. None of them apply: response entity can be converted to String, and response is not closed. So this test should pass (with Response.readEntity() returning "ouch").