changeset 2210:ce3770eadf85

6707226: java.beans.Statement & java.beans.Expression miss one important usecase Reviewed-by: rupashka
author malenkov
date Thu, 11 Mar 2010 17:39:33 +0300
parents 0e0ce1aa1bba
children d86c053ca938
files src/share/classes/java/beans/Expression.java src/share/classes/java/beans/Statement.java test/java/beans/Statement/Test6707226.java
diffstat 3 files changed, 83 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/beans/Expression.java	Thu Mar 11 11:54:17 2010 +0900
+++ b/src/share/classes/java/beans/Expression.java	Thu Mar 11 17:39:33 2010 +0300
@@ -99,6 +99,29 @@
     }
 
     /**
+     * {@inheritDoc}
+     * <p>
+     * If the invoked method completes normally,
+     * the value it returns is copied in the {@code value} property.
+     * Note that the {@code value} property is set to {@code null},
+     * if the return type of the underlying method is {@code void}.
+     *
+     * @throws NullPointerException if the value of the {@code target} or
+     *                              {@code methodName} property is {@code null}
+     * @throws NoSuchMethodException if a matching method is not found
+     * @throws SecurityException if a security manager exists and
+     *                           it denies the method invocation
+     * @throws Exception that is thrown by the invoked method
+     *
+     * @see java.lang.reflect.Method
+     * @since 1.7
+     */
+    @Override
+    public void execute() throws Exception {
+        setValue(invoke());
+    }
+
+    /**
      * If the value property of this instance is not already set,
      * this method dynamically finds the method with the specified
      * methodName on this target with these arguments and calls it.
--- a/src/share/classes/java/beans/Statement.java	Thu Mar 11 11:54:17 2010 +0900
+++ b/src/share/classes/java/beans/Statement.java	Thu Mar 11 17:39:33 2010 +0300
@@ -127,8 +127,8 @@
     }
 
     /**
-     * The execute method finds a method whose name is the same
-     * as the methodName property, and invokes the method on
+     * The {@code execute} method finds a method whose name is the same
+     * as the {@code methodName} property, and invokes the method on
      * the target.
      *
      * When the target's class defines many methods with the given name
@@ -136,7 +136,7 @@
      * the algorithm specified in the Java Language Specification
      * (15.11). The dynamic class of the target and arguments are used
      * in place of the compile-time type information and, like the
-     * <code>java.lang.reflect.Method</code> class itself, conversion between
+     * {@link java.lang.reflect.Method} class itself, conversion between
      * primitive values and their associated wrapper classes is handled
      * internally.
      * <p>
@@ -147,13 +147,22 @@
      * <li>
      * The reserved method name "new" may be used to call a class's constructor
      * as if all classes defined static "new" methods. Constructor invocations
-     * are typically considered <code>Expression</code>s rather than <code>Statement</code>s
+     * are typically considered {@code Expression}s rather than {@code Statement}s
      * as they return a value.
      * <li>
-     * The method names "get" and "set" defined in the <code>java.util.List</code>
+     * The method names "get" and "set" defined in the {@link java.util.List}
      * interface may also be applied to array instances, mapping to
-     * the static methods of the same name in the <code>Array</code> class.
+     * the static methods of the same name in the {@code Array} class.
      * </ul>
+     *
+     * @throws NullPointerException if the value of the {@code target} or
+     *                              {@code methodName} property is {@code null}
+     * @throws NoSuchMethodException if a matching method is not found
+     * @throws SecurityException if a security manager exists and
+     *                           it denies the method invocation
+     * @throws Exception that is thrown by the invoked method
+     *
+     * @see java.lang.reflect.Method
      */
     public void execute() throws Exception {
         invoke();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/beans/Statement/Test6707226.java	Thu Mar 11 17:39:33 2010 +0300
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2010 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6707226
+ * @summary Tests the value updating in Expression
+ * @author Sergey Malenkov
+ */
+
+import java.beans.Expression;
+
+public class Test6707226 {
+    public static void main(String[] args) throws Exception {
+        Object value = new Object();
+
+        Expression expression = new Expression(value, Object.class, "new", null);
+        if (!value.equals(expression.getValue()))
+            throw new Error("the value is updated unexpectedly");
+
+        expression.execute();
+        if (value.equals(expression.getValue()))
+            throw new Error("the value is not updated as expected");
+    }
+}