ICEfaces
  1. ICEfaces
  2. ICE-8181

The @PreDestroy method called twice for WindowScope beans

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.0.1, EE-3.0.0.GA
    • Fix Version/s: 3.1.0.BETA2, 3.1
    • Component/s: Framework
    • Labels:
      None
    • Environment:
      WindowScope
    • Assignee Priority:
      P2

      Description

      I was troubleshooting a problem in IE using the samples/core/test/scopes example and noticed that for our Window-scoped beans, the @PreDestroy marked method is called twice. I added the Thread.dumpStack() calls into the @PreDestroy method of the WindowCounter bean. To replicate the test in the scopes example:

      1) Open the index page
      2) Click the link to the window-scope-test page
      3) Change the counter value
      4) Go back to the index page
      5) Go back to the window-scope-test page

      First it creates an instance when accessing the page with the Window-scoped bean.

      org.icefaces.demo.scopes.WindowScopedCounter@1796a6ac
      created >> org.icefaces.demo.scopes.WindowScopedCounter@1796a6ac

      The first @PreDestroy is when leaving the page with a Window-scoped bean and going back to the index.html (a page with no JSF and no bean references):

      destroyed >> org.icefaces.demo.scopes.WindowScopedCounter@1796a6ac
      java.lang.Exception: Stack trace
      at java.lang.Thread.dumpStack(Thread.java:1273)
      at org.icefaces.demo.scopes.WindowScopedCounter.destroyed(WindowScopedCounter.java:40)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.icefaces.impl.application.WindowScopeManager.callAnnotatedMethod(WindowScopeManager.java:268)
      at org.icefaces.impl.application.WindowScopeManager.notifyPreDestroy(WindowScopeManager.java:201)
      at org.icefaces.impl.application.WindowScopeManager.notifyPreDestroyForAll(WindowScopeManager.java:193)
      at org.icefaces.impl.application.WindowScopeManager.access$1900(WindowScopeManager.java:42)
      at org.icefaces.impl.application.WindowScopeManager$AllWindowsClosedNotifier.run(WindowScopeManager.java:606)
      at java.util.TimerThread.mainLoop(Timer.java:512)
      at java.util.TimerThread.run(Timer.java:462)

      Then if you navigate back to the page with the Window-scoped bean, it destroys it again before restoring the View and creating a new bean instance:

      destroyed >> org.icefaces.demo.scopes.WindowScopedCounter@1796a6ac
      java.lang.Exception: Stack trace
      at java.lang.Thread.dumpStack(Thread.java:1273)
      at org.icefaces.demo.scopes.WindowScopedCounter.destroyed(WindowScopedCounter.java:40)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:117)
      at com.sun.faces.vendor.WebContainerInjectionProvider.invokePreDestroy(WebContainerInjectionProvider.java:87)
      at com.sun.faces.mgbean.BeanBuilder.destroy(BeanBuilder.java:116)
      at com.sun.faces.mgbean.BeanManager.processEvent(BeanManager.java:125)
      at javax.faces.event.SystemEvent.processListener(SystemEvent.java:106)
      at com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:2168)
      at com.sun.faces.application.ApplicationImpl.invokeListenersFor(ApplicationImpl.java:2144)
      at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:295)
      at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:246)
      at org.icefaces.impl.application.WindowScopeManager$ScopeMap.discardIfExpired(WindowScopeManager.java:318)
      at org.icefaces.impl.application.WindowScopeManager$ScopeMap.access$600(WindowScopeManager.java:283)
      at org.icefaces.impl.application.WindowScopeManager.determineWindowID(WindowScopeManager.java:121)
      at org.icefaces.impl.application.WindowScopeManager$DetermineOrDisposeScope.beforePhase(WindowScopeManager.java:538)
      at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99)
      at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
      at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
      ...
      org.icefaces.demo.scopes.WindowScopedCounter@2b73c3aa
      created >> org.icefaces.demo.scopes.WindowScopedCounter@2b73c3aa

        Activity

          People

          • Assignee:
            Mircea Toma
            Reporter:
            Deryk Sinotte
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: