Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-2511

JsonObjects#createBuiltInDependency produces NPE for Instance<?> injection sites

    XMLWordPrintable

Details

    • Bug
    • Resolution: Obsolete
    • Major
    • 2.4.4.Final
    • 2.4.3.Final, 2.4.7.Final
    • Tooling
    • None
    • Hide

      I had to augment the org.wildfly.swarm.container.runtime.ServerBootstrapImpl to enable development mode with export of the data using the org.jboss.weld.development and org.jboss.weld.probe.exportDataAfterDeployment properties:

                          Weld weld = new Weld(WELD_INSTANCE_ID)
                              .property("org.jboss.weld.development", true)
                              .property("org.jboss.weld.probe.exportDataAfterDeployment", "/tmp/");
                          weld.setClassLoader(module.getClassLoader());
      

      Then running a microprofile-jwt fraction unit test produces the NPE.

      Show
      I had to augment the org.wildfly.swarm.container.runtime.ServerBootstrapImpl to enable development mode with export of the data using the org.jboss.weld.development and org.jboss.weld.probe.exportDataAfterDeployment properties: Weld weld = new Weld(WELD_INSTANCE_ID) .property( "org.jboss.weld.development" , true ) .property( "org.jboss.weld.probe.exportDataAfterDeployment" , "/tmp/" ); weld.setClassLoader(module.getClassLoader()); Then running a microprofile-jwt fraction unit test produces the NPE.

    Description

      The weld-probe-core org.jboss.weld.probe.JsonObjects#createBuiltInDependency produces an NPE when a built-in bean is injected using Instance<?> as is the case with this thorntail site:

          @Inject
          private Instance<RuntimeDeployer> deployer;
      

      This ends up being handled by this block of code:

                  if (lazilyFetched != null && !Components.isBuiltinBeanButNotExtension(lazilyFetched)) {
                      JsonObjectBuilder lazilyFetchedDependency = createDependency(lazilyFetched, null, probe); // line 852
                      lazilyFetchedDependency.add(REQUIRED_TYPE, Formats.formatType(Components.getFacadeType(dependency.getInjectionPoint()), false)).add(QUALIFIERS,
                              createQualifiers(dependency.getInjectionPoint().getQualifiers(), false));
                      lazilyFetchedDependency.add(INFO, INFO_FETCHING_LAZILY);
                      lazilyFetchedDependency.add(IS_POTENTIAL, true);
                      builtInDependency.add(type, Json.arrayBuilder().add(lazilyFetchedDependency));
                  }
      

      and the call to createDependency(lazilyFetched, null, probe) at line 852 is guaranteed to produce an NPE on the next line when the lazilyFetchedDependency is used as the createDependency will only return a non-null JsonObjectBuilder if its dependency argument is not null:

          private static JsonObjectBuilder createDependency(Bean<?> bean, Dependency dependency, Probe probe) {
              JsonObjectBuilder builder = null;
              if (bean != null && dependency != null) {
                  builder = createSimpleBeanJson(bean, probe);
                  builder.add(REQUIRED_TYPE, Formats.formatType(dependency.getInjectionPoint().getType(), false)).add(QUALIFIERS,
                          createQualifiers(dependency.getInjectionPoint().getQualifiers(), false));
              }
              return builder;
          }
      

      This is what is seen when enabling development mode in my thorntail fork:

      java.lang.NullPointerException
      	at org.jboss.weld.probe.JsonObjects.createBuiltInDependency(JsonObjects.java:853)
      	at org.jboss.weld.probe.JsonObjects.createDependencies(JsonObjects.java:816)
      	at org.jboss.weld.probe.JsonObjects.createFullBeanJson(JsonObjects.java:565)
      	at org.jboss.weld.probe.JsonObjects.createBeansJson(JsonObjects.java:469)
      	at org.jboss.weld.probe.DefaultJsonDataProvider.receiveBeans(DefaultJsonDataProvider.java:72)
      	at org.jboss.weld.probe.Exports.exportJsonData(Exports.java:45)
      	at org.jboss.weld.probe.ProbeExtension.exportDataIfNeeded(ProbeExtension.java:334)
      	at org.jboss.weld.probe.ProbeExtension.afterDeploymentValidation(ProbeExtension.java:170)
      	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.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:88)
      	at org.jboss.weld.injection.MethodInvocationStrategy$SpecialParamPlusBeanManagerStrategy.invoke(MethodInvocationStrategy.java:144)
      	at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:299)
      	at org.jboss.weld.event.ExtensionObserverMethodImpl.sendEvent(ExtensionObserverMethodImpl.java:124)
      	at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:277)
      	at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:255)
      	at org.jboss.weld.event.ObserverNotifier.notifySyncObservers(ObserverNotifier.java:269)
      	at org.jboss.weld.event.ObserverNotifier.notify(ObserverNotifier.java:258)
      	at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:154)
      	at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:148)
      	at org.jboss.weld.bootstrap.events.AbstractContainerEvent.fire(AbstractContainerEvent.java:53)
      	at org.jboss.weld.bootstrap.events.AbstractDeploymentContainerEvent.fire(AbstractDeploymentContainerEvent.java:35)
      	at org.jboss.weld.bootstrap.events.AfterDeploymentValidationImpl.fire(AfterDeploymentValidationImpl.java:28)
      	at org.jboss.weld.bootstrap.WeldStartup.validateBeans(WeldStartup.java:482)
      	at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:90)
      	at org.jboss.weld.environment.se.Weld.initialize(Weld.java:767)
      	at org.wildfly.swarm.container.runtime.ServerBootstrapImpl.lambda$null$0(ServerBootstrapImpl.java:151)
      	at org.wildfly.swarm.container.runtime.LogSilencer$SilentExecutor.execute(LogSilencer.java:75)
      	at org.wildfly.swarm.container.runtime.ServerBootstrapImpl.lambda$bootstrap$1(ServerBootstrapImpl.java:120)
      	at org.wildfly.swarm.spi.api.ClassLoading.withTCCL(ClassLoading.java:43)
      	at org.wildfly.swarm.container.runtime.ServerBootstrapImpl.bootstrap(ServerBootstrapImpl.java:113)
      	at org.wildfly.swarm.Swarm.start(Swarm.java:398)
      	at org.wildfly.swarm.Swarm.main(Swarm.java:742)
      	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.wildfly.swarm.bootstrap.MainInvoker.invoke(MainInvoker.java:53)
      	at org.wildfly.swarm.bootstrap.Main.run(Main.java:132)
      	at org.wildfly.swarm.bootstrap.Main.main(Main.java:85)
      	at org.jboss.weld.bootstrap.events.AbstractDeploymentContainerEvent.fire(AbstractDeploymentContainerEvent.java:37)
      	at org.jboss.weld.bootstrap.events.AfterDeploymentValidationImpl.fire(AfterDeploymentValidationImpl.java:28)
      	at org.jboss.weld.bootstrap.WeldStartup.validateBeans(WeldStartup.java:482)
      	at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:90)
      	at org.jboss.weld.environment.se.Weld.initialize(Weld.java:767)
      	at org.wildfly.swarm.container.runtime.ServerBootstrapImpl.lambda$null$0(ServerBootstrapImpl.java:151)
      	at org.wildfly.swarm.container.runtime.LogSilencer$SilentExecutor.execute(LogSilencer.java:75)
      	at org.wildfly.swarm.container.runtime.ServerBootstrapImpl.lambda$bootstrap$1(ServerBootstrapImpl.java:120)
      	at org.wildfly.swarm.spi.api.ClassLoading.withTCCL(ClassLoading.java:43)
      	... 10 more
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            starksm64 Scott Stark (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: