Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-9710

Camel Dozer Component - Fails to load custom function due to NPE

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.16.1
    • Fix Version/s: 2.16.3, 2.17.0
    • Component/s: camel-dozer
    • Labels:
      None
    • Environment:

      Any

    • Estimated Complexity:
      Unknown

      Description

      Camel Dozer component throws NPE, when using custom converter as shown in the following example.

      <mapping>
      <class-a>org.example.A</class-a>
      <class-b>org.example.B</class-b>
      <field custom-converter-id="_customMapping"
      custom-converter-param="org.example.CustomMapper,mapCustomer">
      <a>sourceField</a>
      <b>destinationField</b>
      </field>
      </mapping>

      When the sourceField value is null in the Class A,Fails to load custom function and throws RuntimeException caused due to NPE.

      Issue with Code: (
      ------------------------
      Class: CustomMapper
      Method: invokeFunction
      Line# 117

      Object customObj;
      Method method = null;
      try {
      Class<?> customClass = resolver.resolveClass(className);
      customObj = customClass.newInstance();

      // If a specific mapping operation has been supplied use that
      if (operation != null && prmTypesAndValues != null)

      { method = selectMethod(customClass, operation, source, prmTypesAndValues); }

      else if (operation != null)

      { method = customClass.getMethod(operation, source.getClass()); // ***** THIS LINE CAUSES NPE, as source is NULL */ }

      else

      { method = selectMethod(customClass, source); }

      } catch (Exception e)

      { throw new RuntimeException("Failed to load custom function", e); }

      StackTrace:
      -------------------
      java.lang.RuntimeException: Failed to load custom function
      at org.apache.camel.component.dozer.CustomMapper.mapCustom(CustomMapper.java:122)
      at org.apache.camel.component.dozer.CustomMapper.convert(CustomMapper.java:46)
      at org.dozer.MappingProcessor.mapUsingCustomConverterInstance(MappingProcessor.java:977)
      at org.dozer.MappingProcessor.mapFromFieldMap(MappingProcessor.java:355)
      at org.dozer.MappingProcessor.mapField(MappingProcessor.java:307)
      at org.dozer.MappingProcessor.map(MappingProcessor.java:267)
      at org.dozer.MappingProcessor.mapToDestObject(MappingProcessor.java:216)
      at org.dozer.MappingProcessor.createByCreationDirectiveAndMap(MappingProcessor.java:196)
      at org.dozer.MappingProcessor.mapGeneral(MappingProcessor.java:170)
      at org.dozer.MappingProcessor.map(MappingProcessor.java:104)
      at org.dozer.MappingProcessor.map(MappingProcessor.java:99)
      at org.dozer.DozerBeanMapper.map(DozerBeanMapper.java:120)
      at org.apache.camel.component.dozer.DozerProducer.process(DozerProducer.java:82)
      at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
      at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:141)
      at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
      at org.apache.camel.processor.interceptor.HandleFaultInterceptor.process(HandleFaultInterceptor.java:42)
      at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:91)
      at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:460)
      at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)
      at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)
      at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
      at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)
      at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:62)
      at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)
      at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109)
      at org.apache.camel.processor.UnitOfWorkProducer.process(UnitOfWorkProducer.java:68)
      at org.apache.camel.impl.ProducerCache$2.doInProducer(ProducerCache.java:412)
      at org.apache.camel.impl.ProducerCache$2.doInProducer(ProducerCache.java:380)
      at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:270)
      at org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:380)
      at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:221)
      at org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:124)
      at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:137)
      at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:144)
      at com.ta.shop.integration.routes.doz.DozerJsonTest.testDozerHappyPath(DozerJsonTest.java:23)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
      at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
      at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
      at org.junit.rules.RunRules.evaluate(RunRules.java:20)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
      at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
      Caused by: java.lang.NullPointerException
      at org.apache.camel.component.dozer.CustomMapper.mapCustom(CustomMapper.java:117)

        Attachments

          Activity

            People

            • Assignee:
              trohovsky Tomas Rohovsky
              Reporter:
              ranjit.nethi@gmail.com Ranjit Nethi
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: