From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20573 invoked by alias); 17 Apr 2005 00:11:49 -0000 Mailing-List: contact java-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: java-prs-owner@gcc.gnu.org Received: (qmail 20555 invoked by uid 48); 17 Apr 2005 00:11:48 -0000 Date: Sun, 17 Apr 2005 00:11:00 -0000 From: "gruni dot ca at gmail dot com" To: java-prs@gcc.gnu.org Message-ID: <20050417001142.21065.gruni.ca@gmail.com> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug java/21065] New: javax.swing.event.EventListenerList.getListenerList() implemented wrong X-Bugzilla-Reason: CC X-SW-Source: 2005-q2/txt/msg00155.txt.bz2 List-Id: I am using a custom Class wich throws events, by using this I rely on the EventListenerList Class to hold my Eventlisteners. The Method getListenerList is used by the method protected void fireFooXXX() { // Guaranteed to return a non-null array Object[] listeners = listenerList.getListenerList(); // Process the listeners last to first, notifying // those that are interested in this event for (int i = listeners.length-2; i>=0; i-=2) { if (listeners[i]==FooListener.class) { // Lazily create the event: if (fooEvent == null) fooEvent = new FooEvent(this); ((FooListener)listeners[i+1]).fooXXX(fooEvent); } } } which is the standard Method given in the API to fire Events to all EventListeners. This Method relies on the correct implementation of getListenerList() which should according to the API Documentation of Java by SUN http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/event/EventListenerList.html#getListenerList() [quote] getListenerList public Object[] getListenerList() Passes back the event listener list as an array of ListenerType-listener pairs. Note that for performance reasons, this implementation passes back the actual data structure in which the listener data is stored internally! This method is guaranteed to pass back a non-null array, so that no null-checking is required in fire methods. A zero-length array of Object should be returned if there are currently no listeners. WARNING!!! Absolutely NO modification of the data contained in this array should be made -- if any such manipulation is necessary, it should be done on a copy of the array returned rather than the array itself. [/quote] The API doc says "Passes back the event listener list as an array of ListenerType-listener pairs." my understanding of pairs is multiples of two, so the EventListenerList can never contain 1 or 3 entries or any other odd number. But when adding one Eventlistener to such a list it really just adds this EventListener resulting in a getListenerList() which returns one Element, which is simply wrong. A Testcase will follow as soon as I have written one. btw this is my system: WinXP SP2 gcj 4.0 20050324 from thisiscool.com Regards, Andreas -- Summary: javax.swing.event.EventListenerList.getListenerList() implemented wrong Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: critical Priority: P1 Component: java AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: gruni dot ca at gmail dot com CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21065