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

NPE when trying to get BeanManager after container was closed

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved (View Workflow)
    • Major
    • Resolution: Done
    • 3.0.5.Final
    • 4.0.0.CR1
    • 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 { } }

    Description

      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

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: