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

java.lang.reflect.Method.invoke doesn't allow public methods of non-public class

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 1.1
    • core-libs



      Name: mc57594 Date: 05/21/97


      Invocations of public methods in non-public classes are disallowed. This makes it impossible to invoke methods of public interfaces that are implemented by non-public classes, like "hasMoreElmeents" in VectorEnumerator.

      For instance, the following code throws an IllegalAccessException:


      import java.util.Vector;
      import java.lang.reflect.Method;

      public class test {

      public static void main(String[] argv) {
      Vector v = new Vector();
      v.addElement("foo");

      Object o = v.elements();
      Class c = o.getClass();

      Method[] m = c.getDeclaredMethods();

      try {
      for (int i = 0; i < m.length; i++)
      if (m[i].getName().equals("hasMoreElements"))
      System.out.println(m[i].invoke(
      o,new Object[0]));
      }
      catch (Exception e) {
      System.out.println(e);
      }
      }
      }

      I have traced this to line 155 of reflect.c, which calls VerifyClassAccess() and disallows the invocation.
      -Clint

      company - Metrowerks Inc. , email - ###@###.###
      ======================================================================

            apalanissunw Anand Palaniswamy (Inactive)
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: