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

Add bridge method to allow reflective access to public method in non-public class

XMLWordPrintable

    • b65
    • generic
    • generic
    • Verified

      The program below fails at runtime with this error:

      Exception in thread "main" java.lang.IllegalAccessException: Class refl.ClientTest can not access a member of class refl.a.Base with modifiers "public"
              at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
              at java.lang.reflect.Method.invoke(Method.java:578)
              at refl.ClientTest.main(ClientTest.java:9)

      ========== test/refl/a/Base.java ==========
           1 package refl.a;
           2
           3 class Base {
           4 public void f() {
           5 System.out.println("Hello, world!");
           6 }
           7 }
      ========== test/refl/a/Pub.java ==========
           1 package refl.a;
           2
           3 public class Pub extends Base {}
      ========== test/refl/ClientTest.java ==========
           1 package refl;
           2 import refl.a.*;
           3 import java.lang.reflect.*;
           4
           5 public class ClientTest {
           6 public static void main(String[] args) throws Exception {
           7 Pub p = new Pub();
           8 Method m = Pub.class.getMethod("f");
           9 m.invoke(p);
          10 }
          11 }

            ahe Peter Ahe
            ahe Peter Ahe
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: