6707226: java.beans.Statement & java.beans.Expression miss one important usecase
Reviewed-by: rupashka
This commit is contained in:
parent
02e9344ed0
commit
a55a44a6e2
@ -98,6 +98,29 @@ public class Expression extends Statement {
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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
|
||||
|
@ -127,8 +127,8 @@ public class Statement {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 @@ public class Statement {
|
||||
* 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 @@ public class Statement {
|
||||
* <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();
|
||||
|
45
jdk/test/java/beans/Statement/Test6707226.java
Normal file
45
jdk/test/java/beans/Statement/Test6707226.java
Normal file
@ -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");
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user