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

nested cross-package invocation via reflection causes IllegalAccessException

XMLWordPrintable

    • 1.2fcs
    • sparc
    • solaris_2.5
    • Verified



      Name: mgC56079 Date: 09/10/98



      Here is the minimized test demonstrating the bug:
      ==== InvokeTest1.java ====
      package pkg1;

      import java.lang.reflect.*;

      public class InvokeTest1 {

          public static void main(String a[]) {
              try {
                  Object args[] = {};
                  Class params[] = {};
                  Object Ob = new pkg.InvokeTest();
                  Method m = pkg.InvokeTest.class.getDeclaredMethod("test", params);
                  m.invoke( Ob, args );
              } catch (Exception e) {
                  e.printStackTrace();
                  System.out.println("failed 1");
              }
          }

      }

      ==== InvokeTest.java ====
      package pkg;

      import java.lang.reflect.*;

      public class InvokeTest {

          public void test() {
              try {
                  Object args[] = {};
                  Class params[] = {};
                  Object Ob = new SomeClass();
                  Method m = SomeClass.class.getDeclaredMethod("method", params);
                  m.invoke( Ob, args );
                  System.out.println("passed");

              } catch (Exception e) {
                  e.printStackTrace();
                  System.out.println("failed 2");
              }
          }


      }


      class SomeClass {
          public void method() {
          }
      }
      === Sample run (jdk1.1.6, jdk1.2beta4, jdk1.2fcsH; correct) ===
      % javac -d . InvokeTest.java InvokeTest1.java
      % java pkg1.InvokeTest1
      passed

      === Sample run (jdk1.1.6, jdk1.2fcsI; wrong) ===
      % javac -d . InvokeTest.java InvokeTest1.java
      % java pkg1.InvokeTest1
      java.lang.IllegalAccessException: pkg/SomeClass
      at java.lang.reflect.Method.invoke(Native Method)
      at pkg.InvokeTest.test(Compiled Code)
      at java.lang.reflect.Method.invoke(Native Method)
      at pkg1.InvokeTest1.main(Compiled Code)
      failed 2



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

            apalanissunw Anand Palaniswamy (Inactive)
            mgorshen Mikhail Gorshenev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: