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

Javac compiles method reference that allows results in an IllegalAccessError

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 9
    • 8, 9
    • tools
    • 8
    • b96
    • x86_64
    • windows_7
    • Verified

    Backports

      Description

        FULL PRODUCT VERSION :


        A DESCRIPTION OF THE PROBLEM :
        Javac shouldn't allow referencing a method that is out of scope. Either it should produce a compile-time error or it should desugar as in the lambda equivalent.





        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1) Create default-scoped abstract class with concrete method
        2) Create a concrete public class extending the above class in the same package
        3) Use a method reference to this inherited method in a class outside of the package

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Either
        A) compiles the same as map(y -> y.getX())
        B) compile-time error
        ACTUAL -
        IllegalAccessError at runtime

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        package x;
        abstract class X {
        public String getX() { return "x";}

        package x;
        public class Y extends X {}

        package z;
        public class Z {
        public static void main (String[] args) {
          Arrays.asList(new Y()).stream().map(Y::getX).forEach(System.out::println);
        }

        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Use lambda form

        Attachments

          1. X.java
            0.1 kB
          2. Y.java
            0.0 kB
          3. Z.java
            0.3 kB

          Issue Links

            Activity

              People

                sadayapalam Srikanth Adayapalam (Inactive)
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: