Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-2800

NPE when trying to inject an optional @org.eclipse.microprofile.config.inject.ConfigProperty

    XMLWordPrintable

Details

    Description

      Following injection fails with an NPE: 

      @Path("/")
      public class OptionalConfigPropertyInjectionResource {
       
          public static final String OPTIONAL_PROPERTY_NAME = "org.jboss.resteasy.test.optionalProperty";   
      
          @Inject
          @ConfigProperty(name = OPTIONAL_PROPERTY_NAME)
          private Optional<String> optionalProperty;   
      
          @GET
          @Produces("text/plain")
           public String getOptionalProperty(){
               return optionalProperty.orElse(null);
           }
      }
      

       

      Caused by: java.lang.NullPointerException
      	at org.jboss.resteasy.core.InjectorFactoryImpl$OptionalInjections$DelegatingInjector.inject(InjectorFactoryImpl.java:335)
      	at org.jboss.resteasy.core.PropertyInjectorImpl.inject(PropertyInjectorImpl.java:145)
      	at org.jboss.resteasy.cdi.JaxrsInjectionTarget.inject(JaxrsInjectionTarget.java:74)
      	at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:161)
      	at org.jboss.weld.contexts.AbstractContext.get(AbstractContext.java:96)
      	at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:100)
      	at org.jboss.weld.bean.ContextualInstanceStrategy$CachingContextualInstanceStrategy.get(ContextualInstanceStrategy.java:177)
      	at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
      	at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:102)
      	at org.jboss.weld.bean.proxy.ProxyMethodHandler.getInstance(ProxyMethodHandler.java:131)
      	at org.jboss.resteasy.test.microprofile.config.resource.OptionalConfigPropertyInjectionResource$Proxy$_$$_WeldClientProxy.getOptionalProperty(Unknown Source)
      	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)
      

       

      Attachments

        Activity

          People

            rhn-support-asoldano Alessio Soldano
            nicones Nicolas NESMON
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: