Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-ui-dev] Design Question About Listeners & Event Dispatching


I just hit this issue as well while working on
https://bugs.eclipse.org/bugs/show_bug.cgi?id=91343#c13

My plan was to use an iterator so that the more specific exception would be thrown.

My opinion is that it until the runtime implementation is API, it should be fixed on a case by case basis.  It's too bad this got deferred at the last minute for 3.0.  Here we are again near the end of a release...is it too late to get the runtime one made API?  

susan


Douglas Pollock <douglas.pollock@xxxxxxxx>
Sent by: platform-ui-dev-bounces@xxxxxxxxxxx

05/06/2005 11:43 AM
Please respond to dpollock,"Eclipse Platform UI component developers list."

       
        To:        platform-ui-dev@xxxxxxxxxxx
        cc:        
        Subject:        [platform-ui-dev] Design Question About Listeners & Event        Dispatching



My question is whether it should be expected that the list of listeners can be
modified while executing a listener.  Should we always design for this case?  
In other words, should it be possible for a listener to add or remove a
listener while handling an event?


There is a lot of existing code of the following form, or similar but using
iterators.  In the case of iterators, a ConcurrentModificationException will
be thrown.  In the case of indexed access, subtle bugs can exist where
listeners are skipped or handled twice.

       if (activityListeners != null) {
           for (int i = 0; i < activityListeners.size(); i++) {
               ((IActivityListener) activityListeners.get(i))
                       .activityChanged(activityEvent);
                    }
                }

If we write defensively, then we need to do a copy of some sort to avoid
corrupting the collection.

                int commandListenersSize = commandListeners.size();
       if ((commandListeners != null)
               && (commandListenersSize > 0)) {
           final ICommandListener[] listeners = (ICommandListener[])
commandListeners
                   .toArray(new ICommandListener[commandListenersSize]);
           for (int i = 0; i < commandListenersSize; i++) {
               final ICommandListener listener = listeners[i];
               listener.commandChanged(commandEvent);
           }
       }


Should we expend the effort to hunt down the places where we don't defend
against this case?  Or fix them on a case-by-case basis?



cheers,
d.
_______________________________________________
platform-ui-dev mailing list
platform-ui-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/platform-ui-dev


Back to the top