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

Camel-Cdi throws NPE when attempting to inject an array property using Microprofile Config

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.4.3
    • 3.4.4, 3.6.0
    • camel-cdi
    • None
    • JDK 1.8, Tomee 8.0.4 microprofile

    • Unknown

    Description

      Microprofile Configuration supports CDI injection of properties as lists or arrays and can cause the Camel Cdi extension to throw a NPE during container startup:

       

      Caused by: org.apache.webbeans.exception.WebBeansException: java.lang.NullPointerException
       at org.apache.webbeans.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:371)
       at org.apache.webbeans.event.NotificationManager.invokeObserverMethod(NotificationManager.java:819)
       at org.apache.webbeans.event.NotificationManager.fireEvent(NotificationManager.java:715)
       ... 53 more
       Caused by: java.lang.NullPointerException
       at org.apache.camel.cdi.CdiCamelExtension.lambda$shouldDeployDefaultCamelContext$9(CdiCamelExtension.java:320)
       at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:174)
       at java.util.HashMap$KeySpliterator.tryAdvance(HashMap.java:1569)
       at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
       at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
       at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
       at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
       at java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:230)
       at java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:196)
       at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
       at java.util.stream.ReferencePipeline.anyMatch(ReferencePipeline.java:449)
       at org.apache.camel.cdi.CdiCamelExtension.shouldDeployDefaultCamelContext(CdiCamelExtension.java:325)
       at org.apache.camel.cdi.CdiCamelExtension.afterBeanDiscovery(CdiCamelExtension.java:276)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
       at java.lang.reflect.Method.invoke(Method.java:498)
       at org.apache.webbeans.event.ObserverMethodImpl.invoke(ObserverMethodImpl.java:404)
       at org.apache.webbeans.event.ContainerEventObserverMethodImpl.invoke(ContainerEventObserverMethodImpl.java:85)
       at org.apache.webbeans.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:365)
       ... 55 more

       

      This occurs when CdiCamelExtension.shouldDeployDefaultCamelContext encounters a bean for an array type because the Class.getPackage method returns null for arrays:

      private boolean shouldDeployDefaultCamelContext(Set<Bean<?>> beans) {
      
       return beans.stream()
       // Is there a Camel bean with the @Default qualifier?
       // Excluding internal components...
       .filter(bean -> !bean.getBeanClass().getPackage().equals(getClass().getPackage()))
      

       

      Switching around the equals check should fix it.

       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              kentfung Kent Fung
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: