Uploaded image for project: 'CDI Specification Issues'
  1. CDI Specification Issues
  2. CDI-743

NPE when trying to get BeanManager after container was closed

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Obsolete
    • Icon: Major Major
    • None
    • 2.0 .Final, 2.0.SP1
    • 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.

              Unassigned Unassigned
              doychin Doychin Bondzhev (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: