JDK-4076065 : java.beans.VetoableChangeSupport c-tor(source) works wrong with null source
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 1.2.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_2.5
  • CPU: sparc
  • Submitted: 1997-09-03
  • Updated: 1999-01-19
  • Resolved: 1999-01-19
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.
Other
1.2.0 1.2beta2Fixed
Related Reports
Relates :  
Description

Name: dsC58869			Date: 09/03/97



java.beans.VetoableChangeSupport constructor() works wrong if called with null parameter.
It creates an object with invalid state:
firePropertyChange() call causes IllegalArgumentException

This constructor shoud probably throw an IllegalArgumentException 
(as java.util.EventObject does) or a NullPointerException.

java.beans.PropertyChangeSupport has the same problem.

==== Here is the test demonstrating the bug ====

import java.beans.*;

public class TestVCS {
  
  public static void main (String args[]) {
        System.out.println("passing a null source");
       	NewVetoableChangeSupport changes = new NewVetoableChangeSupport(null);
	ChangeHandler alpha = new ChangeHandler();

        System.out.println("adding a listener");
	changes.addVetoableChangeListener(alpha); 

        System.out.println("trying to fire an event");
	alpha.clear();
	try {
	changes.fireVetoableChange("fred", "foo","bah");
	} catch (PropertyVetoException pve) {
	    pve.printStackTrace();
	}
	alpha.checkEvent(changes);

	System.out.println("passed");
        
  }

}

class NewVetoableChangeSupport extends VetoableChangeSupport {
  public NewVetoableChangeSupport(java.lang.Object source) {
    super(source);
  }
}

class ChangeHandler implements VetoableChangeListener {

    private PropertyChangeEvent lastEvent;

    public void vetoableChange(PropertyChangeEvent evt) {
	lastEvent = evt;
    }

    public void checkEvent(Object source) {
        if (lastEvent==null || source!=lastEvent.getSource()) {
		System.out.println("failed: wrong event");
		System.exit(1);
	}
    }

    public void checkNoEvent() {
        if (lastEvent!=null) {
		System.out.println("failed: no event expected");
		System.exit(2);
	}
    }

    public void clear() {
	lastEvent = null;
    }
}

==== Here is the output of the test ====

%java TestVCS
passing a null source
adding a listener
trying to fire an event
java.lang.IllegalArgumentException: null source
	at java.util.EventObject.<init>(EventObject.java:30)
	at java.beans.PropertyChangeEvent.<init>(PropertyChangeEvent.java:54)
	at java.beans.VetoableChangeSupport.fireVetoableChange(VetoableChangeSupport.java:143)
	at TestVCS.main(TestVCS.java:16)

======================================================================

======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic FIXED IN: 1.2beta INTEGRATED IN: 1.2beta2 VERIFIED IN: 1.2fcs
14-06-2004

EVALUATION OK, I've added checks to the PropertyChangeSupport and VetoableChangeSupport constructors for null sources and we throw NullPointerException. KGH 9/19/97
11-06-2004