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

Method reference of a method inherited from an inaccessible class not working

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10
      AdoptOpenJDK (version 15+36) from https://adoptopenjdk.net/.

      A DESCRIPTION OF THE PROBLEM :
      I have a project structure as below

      lib
      ************+
      contains module-info.java as below

      module lib{
        exports pkg;
      }

      and java files as below

      src -> time
      -> Time.java


      public final class Time extends AbstractTime {

      }


      time.internal
      -> AbstractTime.java


      public abstract class AbstractTime<T extends AbstractTime> {

      public int compareTo(AbstractTime time) {
      return 0;
      }
      }
         
        
                
                    

      while trying to access the method compareTo(AbstractTime time) from a different lib called test,

      which contains module-info.java as below

      module module {
        requires lib;
      }


      public final class Main {

        public static void main(String[] args) {
         
          consumeComparator(LocalTime::compareTo); // works as expected
          
          consumeComparator(LocalTime::compareTo); // throws IllegalAccessError
          
        }

        static void consumeComparator(Comparator<LocalTime> comparator) {}
        
       }
        
       Method reference is throwing an IllegalAccessError
       
       Exception in thread "main" java.lang.IllegalAccessError: class root.Main (in module test) cannot access class time.internal.AbstractLocalTime because module time does not export time._internal to module test
      at test/root.Main.main
        
        

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      I have a project structure as below

      lib
      ************+
      contains module-info.java as below

      module lib{
        exports pkg;
      }

      and java files as below

      src -> time
      -> Time.java


      public final class Time extends AbstractTime {

      }


      time.internal
      -> AbstractTime.java


      public abstract class AbstractTime<T extends AbstractTime> {

      public int compareTo(AbstractTime time) {
      return 0;
      }
      }
         
        
                
                    

      while trying to access the method compareTo(AbstractTime time) from a different lib called test,

      which contains module-info.java as below

      module module {
        requires lib;
      }


      public final class Main {

        public static void main(String[] args) {
         
          consumeComparator(LocalTime::compareTo); // works as expected
          
          consumeComparator(LocalTime::compareTo); // throws IllegalAccessError
          
        }

        static void consumeComparator(Comparator<LocalTime> comparator) {}
        
       }
        
       Method reference is throwing an IllegalAccessError
       
       Exception in thread "main" java.lang.IllegalAccessError: class root.Main (in module test) cannot access class time.internal.AbstractLocalTime because module time does not export time._internal to module test
      at test/root.Main.main
        
        

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Both lamda and method reference should be able to call compateTo method
      ACTUAL -
      Method reference failed with IllegalAccessError

      FREQUENCY : always


        Attachments

          Activity

            People

            Assignee:
            vromero Vicente Arturo Romero Zaldivar
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Dates

              Created:
              Updated: