This patch (committed) fixes a bug in JComponent's handling of
VetoableChangeListeners:
2006-06-28 David Gilbert <[EMAIL PROTECTED]>
* java/beans/VetoableChangeSupport.java
(addVetoableChangeListener(VetoableChangeListener)): Do nothing for
null listener,
(addVetoableChangeListener(String, VetoableChangeListener)): Do nothing
for null property name and/or listener,
* javax/swing/JComponent.java
(getListeners): Handle VetoableChangeListener.class as a special case,
(getVetoableChangeListeners): Fetch these from the
vetoableChangeSupport object.
Mauve tests to follow...
Regards,
Dave
Index: java/beans/VetoableChangeSupport.java
===================================================================
RCS file: /sources/classpath/classpath/java/beans/VetoableChangeSupport.java,v
retrieving revision 1.12
diff -u -r1.12 VetoableChangeSupport.java
--- java/beans/VetoableChangeSupport.java 2 Jul 2005 20:32:37 -0000
1.12
+++ java/beans/VetoableChangeSupport.java 28 Jun 2006 14:06:21 -0000
@@ -1,5 +1,6 @@
/* VetoableChangeSupport.java -- support to manage vetoable change listeners
- Copyright (C) 1998, 1999, 2000, 2002, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2002, 2005, 2006,
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -120,14 +121,15 @@
* vetoable change events will be sent to this listener. The listener add
* is not unique: that is, <em>n</em> adds with the same listener will
* result in <em>n</em> events being sent to that listener for every
- * vetoable change. Adding a null listener may cause a NullPointerException
- * down the road. This method will unwrap a VetoableChangeListenerProxy,
+ * vetoable change. This method will unwrap a VetoableChangeListenerProxy,
* registering the underlying delegate to the named property list.
*
- * @param l the listener to add
+ * @param l the listener to add (<code>null</code> ignored).
*/
public synchronized void addVetoableChangeListener(VetoableChangeListener l)
{
+ if (l == null)
+ return;
if (l instanceof VetoableChangeListenerProxy)
{
VetoableChangeListenerProxy p = (VetoableChangeListenerProxy) l;
@@ -215,19 +217,19 @@
* being sent to that listener when that property is changed. The effect is
* cumulative, too; if you are registered to listen to receive events on
* all vetoable changes, and then you register on a particular property,
- * you will receive change events for that property twice. Adding a null
- * listener may cause a NullPointerException down the road. This method
+ * you will receive change events for that property twice. This method
* will unwrap a VetoableChangeListenerProxy, registering the underlying
* delegate to the named property list if the names match, and discarding
* it otherwise.
*
* @param propertyName the name of the property to listen on
* @param l the listener to add
- * @throws NullPointerException if propertyName is null
*/
public synchronized void addVetoableChangeListener(String propertyName,
VetoableChangeListener l)
{
+ if (propertyName == null || l == null)
+ return;
while (l instanceof VetoableChangeListenerProxy)
{
VetoableChangeListenerProxy p = (VetoableChangeListenerProxy) l;
Index: javax/swing/JComponent.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/JComponent.java,v
retrieving revision 1.133
diff -u -r1.133 JComponent.java
--- javax/swing/JComponent.java 28 Jun 2006 12:58:40 -0000 1.133
+++ javax/swing/JComponent.java 28 Jun 2006 14:06:29 -0000
@@ -950,6 +950,8 @@
{
if (listenerType == PropertyChangeListener.class)
return getPropertyChangeListeners();
+ else if (listenerType == VetoableChangeListener.class)
+ return getVetoableChangeListeners();
else
return listenerList.getListeners(listenerType);
}
@@ -968,12 +970,16 @@
/**
* Return all registered <code>VetoableChangeListener</code> objects.
*
- * @return The set of <code>VetoableChangeListener</code> objects in [EMAIL
PROTECTED]
- * #listenerList}
+ * @return An array of the <code>VetoableChangeListener</code> objects
+ * registered with this component (possibly empty but never
+ * <code>null</code>).
+ *
+ * @since 1.4
*/
public VetoableChangeListener[] getVetoableChangeListeners()
- {
- return (VetoableChangeListener[])
getListeners(VetoableChangeListener.class);
+ {
+ return vetoableChangeSupport == null ? new VetoableChangeListener[0]
+ : vetoableChangeSupport.getVetoableChangeListeners();
}
/**