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

@Initialized and @Destroyed event are not fired if a portable extension is used in an app

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 2.2.10.Final, 3.0.0.Alpha7
    • 2.2.9.Final
    • Events
    • None

    Description

      I have a test application using @initialized and @Destoryed to monitor the scope context creation/destory.

      HelloWorldExtensionTestServlet.java
      @WebServlet("/hello")
      public class HelloWorldExtensionTestServlet extends HttpServlet {
      
          @Inject
          HelloWorldExtensionBean hello;
      
          private static EventMetadata beanStartMetaData;
          private static EventMetadata beanStopMetaData;
      
          private static final long serialVersionUID = 8549700799591343964L;
      
          @Override
          protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
      
              PrintWriter pw = response.getWriter();
              pw.write(hello.hello());
              pw.write(beanStartMetaData.getQualifiers().toString());
              pw.write(beanStopMetaData.getQualifiers().toString());
              pw.flush();
              pw.close();
          }
      
          public static void onStart(@Observes @Initialized(RequestScoped.class) Object e, EventMetadata em) {
              if (beanStartMetaData == null) {
                  System.out.println("Initialize Event request scope is happening");
                  beanStartMetaData = em;
              }
          }
          public static void onStop(@Observes @Destroyed(RequestScoped.class) Object e, EventMetadata em) {
              if (beanStopMetaData == null) {
                  System.out.println("Stop Event request scope is happening");
                  beanStopMetaData = em;
              }
          }
      
      }
      
      
      HelloWorldExtensionBean.java
      @RequestScoped
      public class HelloWorldExtensionBean {
      
          public String hello() {
              return "Hello World CDI 1.2!";
          }
      
      }
      

      The application works fine. However, when I added a portal extension in the application, the app has stopped working and a NPE was thrown with the beanStartMetaData and beanStopMetaData null. It seems that the Initialized and Destoryed events are not fired.

      Attachments

        Activity

          People

            rhn-engineering-jharting Jozef Hartinger
            emijiang6 Emily Jiang (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: