[
https://issues.apache.org/jira/browse/CXF-6060?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14187116#comment-14187116
]
Sergey Beryozkin commented on CXF-6060:
---------------------------------------
Right, such code sequence is unlikely to happen in the actual production, the
implementation expects that the out message, properly initialized, is
available. That said I agree that in this case the default providers should be
checked.
> 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)