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

IllegalAccessError trying to access package-private class from VM anonymous class

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 8u60, 9
    • hotspot
    • None
    • b137

      Consider the following case:
        public class p1.IAE {...}
        /*package*/ class p1.Test {...}
        public class p2.AnonClass {...} // VM anonymous class w/ p1.Test provided as a host class.

      If AnonClass tries to access p1.Test the following exception is thrown:
      java.lang.IllegalAccessError: tried to access class p1.T from class p2.AnonClass/1309552426
      at p2.AnonClass/1309552426.test(Unknown Source)
      ... 5 more

      Though AnonClass tries to access package-private in p1 from p2, for VM anonymous class inherit it's host class should be used for all access checks. p1.IAE has access to p1.Test.

      Test case is attached.
      How to run:
        $ javac -XDignore.symbol.file -d . IAE.java
        $ java -Xbootclasspath/a:. p1.IAE

        1. IAE.java
          6 kB
        2. IAE.java
          2 kB

            hseigel Harold Seigel (Inactive)
            vlivanov Vladimir Ivanov
            Votes:
            0 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              Resolved: