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

(reflect) Method.invoke() -- can't call methods privately inherited.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.1, 1.1.3, 1.1.4
    • core-libs
    • generic, x86, sparc
    • solaris_2.5.1, windows_95

      I have

      package P

      protected class A implements B {
          blabla...
      }

      public interface B {
      public void bongo();
      }

      And then I do the things below outside of package P

      B a = somehowGetAHandleOfAnInstanceOfA

      Method m = a.getClass().getMethod("bongo", new Class[] {Void.class});

      When I do

      m.invoke(a, null);

      I get a IllegalAccessException.

      At least the docs should point out this behavior (so it's at least a docu bug).
      I don't know if the behavior is not a bug.
      getMethod should work for all methods that A understands.
      After all I can do a.bongo(), and reflection should support
      everything that can be done directly.

      The workaround is

      a.getInterfaces() and then look in the interfaces for the right Method instance.



            apalanissunw Anand Palaniswamy (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: