Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4531018

Statement.execute() method does not find the most specific method correctly.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • None
    • 1.4.0
    • client-libs
    • sparc
    • solaris_2.6

    Description



      Name: dsR10051 Date: 11/23/2001


      The method of class java.beans.Statement
      public void execute() throws Exception
      does not find the most specific method correctly.
      If target class declares two methods with the same name and type of
      one parameter A or B, where A is a superclass of B,
      and Statement is created with this target, method name and B type argument,
      then execute() method can invoke method with A type argument on target.
      This behavior depends on the order of method declaration.

      Here is minimized test:
      --- StatementTest_1 ---
      import java.beans.*;

      public class StatementTest_1 {

          public static void main (String[] args) {
              StatementTest_1 target = new StatementTest_1();
              String methodName = "method_1";
              B argument0 = new B();
              Object[] arguments = {argument0};
              Statement statement = new Statement(target, methodName, arguments);
              System.out.println("I.");
              try {
                  System.out.print("Execute: ");
                  statement.execute();
              } catch (Exception e) {
                  e.printStackTrace();
              }
              System.out.print("Direct invocation: ");
              target.method_1(argument0);

              System.out.println("II.");
              System.out.println("Enother order of method declarations");

              methodName = "method_2";
              statement = new Statement(target, methodName, arguments);
              try {
                  System.out.print("Execute: ");
                  statement.execute();
              } catch (Exception e) {
                  e.printStackTrace();
              }
              System.out.print("Direct invocation: ");
              target.method_2(argument0);
          }

          public void method_1 (A a) {
              System.out.println("method_1(A) called");
          }
          public void method_1 (B b) {
              System.out.println("method_1(B) called");
          }
              
          public void method_2 (B b) {
              System.out.println("method_2(B) called");
          }
          public void method_2 (A a) {
              System.out.println("method_2(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_1
      I.
      Execute: method_1(A) called
      Direct invocation: method_1(B) called
      II.
      Enother order of method declarations
      Execute: method_2(B) called
      Direct invocation: method_2(B) called
      -----------------------
      We can see that fist part of test failed: Statement.execute() method
      should invoke method_1(B).

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

      Attachments

        Issue Links

          Activity

            People

              mdavidsosunw Mark Davidson (Inactive)
              sdasunw Sda Sda (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: