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

No visibility bridges are created for generic methods

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8, 9, 10
    • Fix Version/s: 13
    • Component/s: tools
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                sadayapalam Srikanth Adayapalam
                Reporter:
                winterhalter Rafael Winterhalter
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: