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

No visibility bridges are created for generic methods

XMLWordPrintable

    • generic
    • generic

      javac is normally adding visibility bridges for methods if they are public but declared by a package-private class:

      /* package-private */ class SuperClass {
        public Object foo() { return null; }
      }
      public class SubClass extends SuperClass { }

      This is not the case if a method has a generic type:

      /* package-private */ class SuperClass<X> {
        public X foo() { return null; }
      }
      public class SubClass extends SuperClass<Void> { }

      As a result, reflective access of this method fails with an IllegalAccessException if the following code is run from outside the package of SuperClass and SubClass:

      SubClass.class.getMethod("foo").invoke(new SubClass());

      I would expect javac to create a visibility bridge for the method in question to allow for reflective access.

            sadayapalam Srikanth Adayapalam (Inactive)
            winterhalter Rafael Winterhalter
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: