JDK-4994635 : Null Pointer adding VetoableChangeListenerProxy to VetoableChangeSupport
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2004-02-13
  • Updated: 2010-07-09
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b03Fixed
Related Reports
Relates :  
Description
Name: gm110360			Date: 02/13/2004


FULL PRODUCT VERSION :
java version "1.4.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)

FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
Here is a comparison of the source code for VetoableChangeSupport and PropertyChangeSupport

First PropertyChangeSupport
/**
     * Add a PropertyChangeListener to the listener list.
     * The listener is registered for all properties.
     *
     * @param listener  The PropertyChangeListener to be added
     */
    public synchronized void addPropertyChangeListener(
				PropertyChangeListener listener) {
	
	if (listener instanceof PropertyChangeListenerProxy) {
	    PropertyChangeListenerProxy proxy =
                   (PropertyChangeListenerProxy)listener;
	    // Call two argument add method.
	    addPropertyChangeListener(proxy.getPropertyName(),
                    (PropertyChangeListener)proxy.getListener());
	} else {
	    if (listeners == null) {
		listeners = new java.util.Vector();
	    }
	    listeners.addElement(listener);
	}
    }
Now VetoableChangeSupport
/**
     * Add a VetoableListener to the listener list.
     * The listener is registered for all properties.
     *
     * @param listener  The VetoableChangeListener to be added
     */

    public synchronized void addVetoableChangeListener(
					VetoableChangeListener listener) {
        if (listener instanceof VetoableChangeListenerProxy) {
            VetoableChangeListenerProxy proxy =
                    (VetoableChangeListenerProxy)listener;
            // Call two argument add method.
            addVetoableChangeListener(proxy.getPropertyName(),
                    (VetoableChangeListener)proxy.getListener());
        } else {
            if (listeners == null) {
                listeners = new java.util.Vector();
            }
        }
        listeners.addElement(listener);
    }

Notice the different location of listeners.addElement(listener);
In the veto version, listeners has not been initialised.  The first time you try to add a VetoableChangeListenerProxy, listeners is null, therefore a NullPointerException is caused when trying to addElement

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
initialise a VetoableChangeSupport object and add a ListenerProxy as above

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected result is to be the same as adding PropertyChangeListenerProxy to PropertyChangeSupport
ACTUAL -
NullPointerException

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NullPointerException
        at java.beans.VetoableChangeSupport.addVetoableChangeListener(VetoableChangeSupport.java:65)
        at uk.co.capacitas.smart.network.ChangeAdapter.addListener(NetworkElement.java:428)
        at uk.co.capacitas.smart.network.NetworkElement.addListener(NetworkElement.java:251)
        at uk.co.capacitas.smart.network.CompositeNetworkElement.addComponent(CompositeNetworkElement.java:100)
        at uk.co.capacitas.smart.network.NetworkNode.addNodeInterface(NetworkNode.java:229)
        at uk.co.capacitas.smart.network.NetworkBuilder.addNetworkSiteService(NetworkBuilder.java:71)
        at uk.co.capacitas.smart.network.ConcreteNetworkManager.addNetworkSiteService(ConcreteNetworkManager.java:141)
        at uk.co.capacitas.smart.testharness.TestBuilder.addSites(TestBuilder.java:234)
        at uk.co.capacitas.smart.testharness.TestBuilder.buildNetwork(TestBuilder.java:101)
        at uk.co.capacitas.smart.testharness.TestBuilder.buildNetwork(TestBuilder.java:121)
        at uk.co.capacitas.smart.testharness.TestHarness.build(TestHarness.java:51)
        at uk.co.capacitas.smart.testharness.TestHarnessTest.testRun(TestHarnessTest.java:50)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at uk.co.capacitas.smart.testharness.TestHarnessTest.main(TestHarnessTest.java:26)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.beans.*;

public class Tester {
    
    public Tester() {
    }
    
    public static void main(String[] args) {
        Tester tester = new Tester();
        VetoableChangeSupport changeSupport = new VetoableChangeSupport(tester);
        
        VetoableChangeListener listener = new VetoableChangeListener(){
            public void vetoableChange(PropertyChangeEvent e) {
            
            }
        };
        VetoableChangeListenerProxy proxy = new VetoableChangeListenerProxy("property",listener);
        changeSupport.addVetoableChangeListener(proxy);
        
    }
    
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Not using a proxy works fine
(Incident Review ID: 185508) 
======================================================================

Comments
EVALUATION VetoableChangeSupport should be similar to PropertyChangeSupport.
23-10-2006

EVALUATION Contribution forum : https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?forumID=1463&messageID=15001 (Three related bug-IDs: 4994635, 5026703, 6225071)
24-08-2006

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: dragon
14-06-2004

EVALUATION This is reproducible back through 1.4, when VetoableChangeListenerProxy was added. Looks like it was simply an oversight when support was added for getListeners(). See delta 1.35 of PropertyChangeSupport versus 1.37 of VetoableChangeSupport. Fix is trivial. ###@###.### 2004-02-19
19-02-2004