Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-6588

NPE in providers.getMessageBodyReader

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.1.2
    • Fix Version/s: 3.1.3, 3.0.7
    • Component/s: JAX-RS
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      I have this ParamConverter:

      @Provider
      @Component
      public class JacksonParamConverterProvider
          implements ParamConverterProvider
      {
          private final JsonMapperConfigurator jsonMapperConfigurator;
      
          @Context
          private Providers providers;
      
          public JacksonParamConverterProvider()
          {
              ObjectMapper objectMapper = new ObjectMapper();
              this.jsonMapperConfigurator =
                  new JsonMapperConfigurator( objectMapper, new Annotations[]{ Annotations.JAXB, Annotations.JACKSON } );
          }
      
      
      
      
          @Override
          public <T> ParamConverter<T> getConverter( Class<T> rawType, Type genericType, Annotation[] annotations )
          {
              MessageBodyReader<T> messageBodyReader = providers.getMessageBodyReader( rawType,
                                                                                       genericType,
                                                                                       annotations,
                                                                                       MediaType.APPLICATION_JSON_TYPE );
      
              if ( messageBodyReader == null || !messageBodyReader.isReadable( rawType, genericType, annotations, MediaType.APPLICATION_JSON_TYPE ) ) {
                  return null;
              }
      
              if ( canConvert( rawType ) )
              {
                  return new ParamConverter<T>()
                  {
                      @Override
                      public T fromString( String value )
                      {
                          ObjectReader objectReader = getObjectMapper().readerFor( rawType );
                          try
                          {
                              return objectReader.readValue( value );
                          }
                          catch ( IOException e )
                          {
                              throw new ProcessingException( e );
                          }
                      }
      
                      @Override
                      public String toString( T value )
                      {
                          try
                          {
                              return getObjectMapper().writerFor( rawType ).writeValueAsString( value );
                          }
                          catch ( JsonProcessingException e )
                          {
                              throw new ProcessingException( e );
                          }
                      }
                  };
              }
              else
              {
                  return null;
              }
          }
      
          private ObjectMapper getObjectMapper()
          {
              return jsonMapperConfigurator.getConfiguredMapper();
          }
      
          private boolean isNotSimpleType( Class<?> rawType )
          {
              return ! ( rawType.getPackage().getName().startsWith( "java.lang" ) || ClassUtils.isPrimitiveOrWrapper( rawType ) );
          }
      
          private boolean canConvert( Class<?> rawType )
          {
              return isNotSimpleType( rawType ) && getObjectMapper().canSerialize( rawType );
          }
      

      which will get an NPE when calling getMessageBodyReader:

      java.lang.NullPointerException: null
      	at org.apache.cxf.jaxrs.impl.tl.ThreadLocalProviders.getMessageBodyReader(ThreadLocalProviders.java:39) ~[cxf-rt-frontend-jaxrs-3.1.2.jar:3.1.2]
      	at com.edb.fs.tac.jfr.srv.ws.jaxrs.JacksonParamConverterProvider.getConverter(JacksonParamConverterProvider.java:50) ~[classes/:na]
      	at org.apache.cxf.jaxrs.provider.ProviderFactory.createParameterHandler(ProviderFactory.java:256) ~[cxf-rt-frontend-jaxrs-3.1.2.jar:3.1.2]
      	at org.apache.cxf.jaxrs.client.AbstractClient.convertParamValue(AbstractClient.java:742) ~[cxf-rt-rs-client-3.1.2.jar:3.1.2]
      	at org.apache.cxf.jaxrs.client.AbstractClient.header(AbstractClient.java:139) ~[cxf-rt-rs-client-3.1.2.jar:3.1.2]
      	at org.apache.cxf.jaxrs.client.WebClient.header(WebClient.java:846) ~[cxf-rt-rs-client-3.1.2.jar:3.1.2]
      	at org.apache.cxf.jaxrs.client.WebClient.header(WebClient.java:83) ~[cxf-rt-rs-client-3.1.2.jar:3.1.2]
      	at com.edb.fs.tac.jfr.srv.ws.AbstractJaxRsSpringWithMocksTest.setHttpHeaders(AbstractJaxRsSpringWithMocksTest.java:109) ~[test-classes/:na]
      	at com.edb.fs.tac.jfr.srv.ws.AbstractJaxRsSpringWithMocksTest.getWebClient(AbstractJaxRsSpringWithMocksTest.java:63) ~[test-classes/:na]
      	at com.edb.fs.tac.jfr.srv.ws.AbstractJaxRsSpringWithMocksTest.getClientProxy(AbstractJaxRsSpringWithMocksTest.java:79) ~[test-classes/:na]
      	at com.edb.fs.tac.jfr.srv.ws.service.customer.CustomerResourceIntegrationTest.testWithComplexQueryObjectWithSubComplexTypes(CustomerResourceIntegrationTest.java:69) ~[test-classes/:na]
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_60]
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_60]
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_60]
      	at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_60]
      	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) ~[junit-4.12.jar:4.12]
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) ~[junit-4.12.jar:4.12]
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) ~[junit-4.12.jar:4.12]
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) ~[junit-4.12.jar:4.12]
      	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) ~[spring-test-4.2.1.RELEASE.jar:4.2.1.RELEASE]
      	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:85) ~[spring-test-4.2.1.RELEASE.jar:4.2.1.RELEASE]
      	at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55) ~[junit-4.12.jar:4.12]
      	at org.junit.rules.RunRules.evaluate(RunRules.java:20) [junit-4.12.jar:4.12]
      	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:86) [spring-test-4.2.1.RELEASE.jar:4.2.1.RELEASE]
      	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) [junit-4.12.jar:4.12]
      	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:241) [spring-test-4.2.1.RELEASE.jar:4.2.1.RELEASE]
      	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87) [spring-test-4.2.1.RELEASE.jar:4.2.1.RELEASE]
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) [junit-4.12.jar:4.12]
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) [junit-4.12.jar:4.12]
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) [junit-4.12.jar:4.12]
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) [junit-4.12.jar:4.12]
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) [junit-4.12.jar:4.12]
      	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) [junit-4.12.jar:4.12]
      	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) [spring-test-4.2.1.RELEASE.jar:4.2.1.RELEASE]
      	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) [spring-test-4.2.1.RELEASE.jar:4.2.1.RELEASE]
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:363) [junit-4.12.jar:4.12]
      	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180) [spring-test-4.2.1.RELEASE.jar:4.2.1.RELEASE]
      	at org.junit.runner.JUnitCore.run(JUnitCore.java:137) [junit-4.12.jar:4.12]
      	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78) [junit-rt.jar:na]
      	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212) [junit-rt.jar:na]
      	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68) [junit-rt.jar:na]
      

      I am running with localtransport.

        Attachments

          Activity

            People

            • Assignee:
              sergey_beryozkin Sergey Beryozkin
              Reporter:
              davidkarlsen@gmail.com David J. M. Karlsen
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: