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

NPE when trying to get BeanManager after container was closed

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 4.0.0.CR1
    • 3.0.5.Final
    • None
    • None
    • Hide

      Try to run this application:

      import javax.enterprise.inject.se.SeContainer;
      import javax.enterprise.inject.se.SeContainerInitializer;
      import javax.enterprise.inject.spi.CDI;
      
      public class NPEOnSecondGetBeanManager {
      
          public static void main(String[] args) {
              SeContainer container = SeContainerInitializer.newInstance()
                                                            .disableDiscovery()
                                                            .addBeanClasses(BeanClass.class)
                                                            .initialize();
              CDI.current().getBeanManager();
              container.close();
      
              CDI.current().getBeanManager();
          }
      
          public static class BeanClass {
          }
      }
      
      Show
      Try to run this application: import javax.enterprise.inject.se.SeContainer; import javax.enterprise.inject.se.SeContainerInitializer; import javax.enterprise.inject.spi.CDI; public class NPEOnSecondGetBeanManager { public static void main( String [] args) { SeContainer container = SeContainerInitializer.newInstance() .disableDiscovery() .addBeanClasses(BeanClass.class) .initialize(); CDI.current().getBeanManager(); container.close(); CDI.current().getBeanManager(); } public static class BeanClass { } }

      CDI.current() should produce IllegalStateException when there is no active container at the moment.

      Instead on the second call in the sample application CDI.current() returns null and that results in NPE.

      The problem is in the implementation of WeldSEProvider.getCDI()

      It should not return null if there is no active container. Instead it should produce IllegalStateException

              manovotn Matěj Novotný
              doychin Doychin Bondzhev (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: