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

NPE when trying to get BeanManager after container was closed

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 3.0.5.Final
    • Fix Version/s: 4.0.0.CR1
    • Component/s: None
    • Labels:
      None
    • Steps to Reproduce:
      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

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

                Dates

                Created:
                Updated:
                Resolved: