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

(reflection) Class.getMethods() allows access to <clinit> of interfaces

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.2.0
    • core-libs
    • None

      using getMethods() on interfaces allows you to see the static initializer for the interface if it has one. here's a test case.

      import java.lang.reflect.*;

      interface i {
          // cause the interface to have a static initializer
          Object o = new Object();
      }

      public class r {
          public static void main(String[] args) throws Exception {
      Method[] methods = Class.forName("i").getMethods();
      for (int i = 0; i < methods.length; i++) {
      if (methods[i].getName().equals("<clinit>"))
      throw new InternalError("shouldn't see clinit");
      }

          }
      }

            wmaddoxsunw William Maddox (Inactive)
            never Tom Rodriguez
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: