DetachEvent fired twice

My app is tab-based, adding each new navigated view in its own tab.

I have some component which is displayed in a form, on top of other content. This form has its own view, appart from the one that is displayed at first on its corresponding tab. The form can be closed independently withouth closing the tab.

The component runs a background thread for updating the contents. I’m using server pushes for authomatic refreshing.

As I want to end this thread when the component is “removed”, either via closing the form (but keeping the rest of the contents that are being displayed in the tab) or via closing the tab, I have added a DetachListener, and inside the detach() method I cancel and purge the thread.

After some NPE (because the detach() method was performing some other cleaning actions), I discovered that, if I “remove” the component by closing just the form that holds it, the event is fired once, thus everything working fine.

But if I close the “entire” tab, the DetachEvent runs
, thus causing some NPE when trying to perform some actions on some objects that I previously nullified when the first event was fired.

I can avoid the NPE by simply not nullifying anything, and on second run cancelling and puring the already cancelled thread won’t have any negative effect, but I don’t understand why is this happing and it looks to me like something is not being done right.

Looks like if closing the tab also closes in cascade the form, thus firing the Detach event for the component I’ve set the listener on… Does this make sense? Do I have to mind for this at all? Is it some sort of bug maybe??