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

Class.getMethods() returns non-public <clinit> method of interface

XMLWordPrintable

    • kestrel
    • generic, sparc
    • generic, solaris_2.5.1, solaris_2.6



      Name: laC46010 Date: 11/05/98


      If an interface contains <clinit> method then Class.getMethods()
      returns it along with other public methods although <clinit>
      is not public.

      In the Java Platform 1.2 API Specification reads:
      "public Method[] getMethods()throws SecurityException

      Returns an array containing Method objects reflecting all the public
      member methods of the class or interface represented by this Class
      object, including those declared by the class or interface and and
      those inherited from superclasses and superinterfaces."

      This bug is reproduced under all JDK versions from jdk1.1 to jdk1.2fcsP

      The example below produces the following output.
      -----------------output------------------
      static <clinit>
      ---------------Test.java-----------------
      import java.lang.reflect.Method;
      import java.lang.reflect.Modifier;

      interface TestedInterface {
          String s = System.getProperty("Test");
      }

          
      public class Test {
          public static void main(String args[]) {
              try {
                  Class c = Class.forName("TestedInterface");
                  Method meth[] = c.getMethods();
                  for (int i = 0; i < meth.length; i++)
                      System.out.println(Modifier.toString(meth[i].getModifiers()) +
                                         " " + meth[i].getName());
              } catch (Throwable t) {
                  t.printStackTrace();
              }
          }
      }

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

            apalanissunw Anand Palaniswamy (Inactive)
            leosunw Leo Leo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: