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

(reflect) Class.getMethods does not return all methods

    Details

      Description



      Name: erR10175 Date: 07/15/2002


       
      New JCK-1.4a testcase

      api/java_lang/Class/index.html#Reflect2[Class2236]

      fails with the following message:
      Class2236: Failed. getMethods() returns array that does not include public java.lang.Exception
      javasoft.sqe.tests.api.java.lang.Class.Overloader.m1(java.lang.Object)

      The specification of the method reads:
      "If the class declares multiple public member methods with the same parameter types,
      they are all included in the returned array."

      In the test the class javasoft.sqe.tests.api.java.lang.Class.Overloader has three
      public methods named "m1" with the same parameter type java.lang.Object. Those
      methods differ in return types that are Object, Throwable and Exception. The only
      returned method with signature "m1(Object)" is "public java.lang.Throwable
      javasoft.sqe.tests.api.java.lang.Class.Overloader.m1(java.lang.Object)". According
      to the spec all three methods are expected to be returned.

      To reproduce the failure put the attached file Overloader.class
      (see Overloader.jasm below for the source of the class) to the current directory
      then compile and run Class2236.java (see below) as the following log shows:
      $java -version && javac Class2236.java && java Class2236; echo $?
      java version "1.4.1-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b11)
      Java HotSpot(TM) Client VM (build 1.4.1-beta-b11, mixed mode)
      public java.lang.Throwable Overloader.m1(java.lang.Throwable)
      public java.lang.Throwable Overloader.m1(java.lang.Object)
      public native int java.lang.Object.hashCode()
      public final native java.lang.Class java.lang.Object.getClass()
      public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException
      public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
      public final void java.lang.Object.wait() throws java.lang.InterruptedException
      public boolean java.lang.Object.equals(java.lang.Object)
      public java.lang.String java.lang.Object.toString()
      public final native void java.lang.Object.notify()
      public final native void java.lang.Object.notifyAll()
      getMethods() returns array that does not include public java.lang.Exception Overloader.m1(java.lang.Object)
      1

      Note, that the test passes with jdk1.4.0 and all Hopper's builds up to b10 as
      the following log shows:
      $java -version && javac Class2236.java && java Class2236; echo $?
      java version "1.4.1-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b10)
      Java HotSpot(TM) Client VM (build 1.4.1-beta-b10, mixed mode)
      public java.lang.Throwable Overloader.m1(java.lang.Throwable)
      public java.lang.Throwable Overloader.m1(java.lang.Object)
      public java.lang.Object Overloader.m1(java.lang.Object)
      public java.lang.Exception Overloader.m1(java.lang.Object)
      public native int java.lang.Object.hashCode()
      public final native java.lang.Class java.lang.Object.getClass()
      public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException
      public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
      public final void java.lang.Object.wait() throws java.lang.InterruptedException
      public boolean java.lang.Object.equals(java.lang.Object)
      public java.lang.String java.lang.Object.toString()
      public final native void java.lang.Object.notify()
      public final native void java.lang.Object.notifyAll()
      OKAY
      0

      ----------------------- Class2236.java
      import java.lang.reflect.Method;

      class Class2236 {
          public static void exit(int retCode, String msg) {
              System.out.println(msg);
              System.exit(retCode);
          }

          public static void main(String[] args) {
              try {
                  Method[] ma = Overloader.class.getMethods();
                  if (ma == null) {
                      exit(1, "getMethods() returns null");
                  }
                  java.util.Vector expectedMethods = new java.util.Vector();
                  expectedMethods.add("public java.lang.Throwable Overloader.m1(java.lang.Throwable)");
                  expectedMethods.add("public java.lang.Throwable Overloader.m1(java.lang.Throwable)");
                  expectedMethods.add("public java.lang.Throwable Overloader.m1(java.lang.Object)");
                  expectedMethods.add("public java.lang.Object Overloader.m1(java.lang.Object)");
                  expectedMethods.add("public java.lang.Exception Overloader.m1(java.lang.Object)");
                  java.util.Vector gotMethods = new java.util.Vector();
                  for (int i = 0; i < ma.length; ++i) {
                      gotMethods.add(ma[i].toString());
                      System.out.println(ma[i]);
                  }
                  for (int i = expectedMethods.size(); --i >= 0; --i) {
                      if (!gotMethods.contains(expectedMethods.get(i))) {
                          exit(1, "getMethods() returns array that does not include " + expectedMethods.get(i));
                      }
                  }
              } catch (SecurityException se){
                  exit(0, "" + se);
              }
          
              exit(0, "OKAY");
          }
      }
      --------------------------------------

      ----------------------- Overloader.jasm
      /*
       * this class has three methods named "m1"
       * with the same parameter types, their return types are
       * Object, Throwable and Exception.
       */
      class Overloader
      {

      public Method m1:"(Ljava/lang/Throwable;)Ljava/lang/Throwable;"
      stack 1 locals 2
      {
      aconst_null;
      areturn;
      }

      public Method m1:"(Ljava/lang/Object;)Ljava/lang/Throwable;"
      stack 1 locals 2
      {
      aconst_null;
      areturn;
      }

      public Method m1:"(Ljava/lang/Object;)Ljava/lang/Object;"
      stack 1 locals 2
      {
      aconst_null;
      areturn;
      }

      public Method m1:"(Ljava/lang/Object;)Ljava/lang/Exception;"
      stack 1 locals 2
      {
      aconst_null;
      areturn;
      }

      } // end Class Overloader
      --------------------------------------

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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                iris Iris Clark
                Reporter:
                reysunw Rey Rey (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: