Name: dsR10051 Date: 11/23/2001
The behavior of method
public void execute() throws Exception
in class java.beans.Statement is not follow to specification.
Javadoc for this method says:
/**
* The execute method finds a method whose name is the same
* as the methodName property, and invokes the method on
* the target.
*
* When the target's class defines many methods with the given name
* the implementation should choose the most specific method using
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* 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
* primitive values and their associated wrapper classes is handled
* internally.
...
*/
public void execute() throws Exception {
Algorithm declares compile-time error if no method is the most
specific (because there are two or more maximally specific methods).
In this case execute() method should throw Exception to satisfy
the specification.
The following example demonstrates that no exception occurs during
the execute() method invokation in this case.
--- StatementTest_2.java ---
import java.beans.*;
public class StatementTest_2 {
public static void main (String[] args) {
StatementTest_2 target = new StatementTest_2();
String methodName = "method_1";
B argument0 = new B();
B argument1 = new B();
Object[] arguments = {argument0, argument1};
Statement statement = new Statement(target, methodName, arguments);
try {
statement.execute();
} catch (Exception e) {
e.printStackTrace();
System.out.println("OKAY");
return;
}
System.out.println("Failed: Exception expected");
System.out.println("reference to method_1 is ambiguous,");
System.out.println("both StatementTest_2.method_1(A,B) and " +
"StatementTest_2.method_1(B,A) match");
// target.method_1(argument0, argument1);
}
public void method_1 (A a, B b) {
System.out.println("method_1(A, B) called");
}
public void method_1 (B b, A a) {
System.out.println("method_1(B, A) called");
}
}
--- A.java ---
public class A {
}
--- B.java ---
public class B extends A {
}
--- Output ---
/set/jdk-builds/JDK1.4.0beta2-b86/solaris/bin/java StatementTest_2
method_1(A, B) called
Failed: Exception expected
reference to method_1 is ambiguous,
both StatementTest_2.method_1(A,B) and StatementTest_2.method_1(B,A) match
--------------
If target.method_1(argument0, argument1) call is uncommented in the example,
compile-time error occurs:
/set/jdk-builds/JDK1.4.0beta2-b86/solaris/bin/javac StatementTest_2.java
StatementTest_2.java:23: reference to method_1 is ambiguous, both method method_1(A,B) in StatementTest_2 and method method_1(B,A) in StatementTest_2 match
target.method_1(argument0, argument1);
^
1 error
----------------------------
======================================================================