You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Nikolai Amelichev (JIRA)" <ji...@apache.org> on 2014/10/23 19:37:34 UTC

[jira] [Created] (CXF-6060) Calling readEntity() on Response created by Response.build() causes NullPointerException

Nikolai Amelichev created CXF-6060:
--------------------------------------

             Summary: Calling readEntity() on Response created by Response.build() causes NullPointerException
                 Key: CXF-6060
                 URL: https://issues.apache.org/jira/browse/CXF-6060
             Project: CXF
          Issue Type: Bug
          Components: JAX-RS
    Affects Versions: 3.0.1
         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)
            Reporter: Nikolai Amelichev


This small test:

{code:java}
@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));
}
{code}

unexpectedly throws `NullPointerException` with the following stacktrace:
{noformat}
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)
{noformat}
(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"}}).



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)