7087429: Constructor of java.beans.PropertyChangeEvent should declare thrown NPE for null source
Reviewed-by: rupashka
--- a/jdk/src/share/classes/java/beans/PropertyChangeEvent.java Thu Nov 10 17:35:16 2011 +0400
+++ b/jdk/src/share/classes/java/beans/PropertyChangeEvent.java Thu Nov 10 17:37:29 2011 +0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,8 @@
package java.beans;
+import java.util.EventObject;
+
/**
* A "PropertyChange" event gets delivered whenever a bean changes a "bound"
* or "constrained" property. A PropertyChangeEvent object is sent as an
@@ -42,21 +44,21 @@
* arbitrary set of if its properties have changed. In this case the
* old and new values should also be null.
*/
-
-public class PropertyChangeEvent extends java.util.EventObject {
+public class PropertyChangeEvent extends EventObject {
private static final long serialVersionUID = 7042693688939648123L;
/**
- * Constructs a new <code>PropertyChangeEvent</code>.
+ * Constructs a new {@code PropertyChangeEvent}.
*
- * @param source The bean that fired the event.
- * @param propertyName The programmatic name of the property
- * that was changed.
- * @param oldValue The old value of the property.
- * @param newValue The new value of the property.
+ * @param source the bean that fired the event
+ * @param propertyName the programmatic name of the property that was changed
+ * @param oldValue the old value of the property
+ * @param newValue the new value of the property
+ *
+ * @throws IllegalArgumentException if {@code source} is {@code null}
*/
public PropertyChangeEvent(Object source, String propertyName,
- Object oldValue, Object newValue) {
+ Object oldValue, Object newValue) {
super(source);
this.propertyName = propertyName;
this.newValue = newValue;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/beans/PropertyChangeSupport/Test7087429.java Thu Nov 10 17:37:29 2011 +0400
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7087429
+ * @summary Tests IllegalArgumentException from the PropertyChangeEvent constructor
+ * @author Sergey Malenkov
+ */
+
+import java.beans.PropertyChangeEvent;
+
+public final class Test7087429 {
+ public static void main(String[] args) {
+ try {
+ new PropertyChangeEvent(null, null, null, null);
+ }
+ catch (IllegalArgumentException exception) {
+ if (exception.getMessage().equals("null source")) {
+ return;
+ }
+ }
+ throw new Error("IllegalArgumentException expected");
+ }
+}