Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-11301

References to inaccesible methods with static compilation leads to runtime error

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 5.0.0-alpha-6
    • Static compilation
    • None

    Description

      I have the following ill-typed program

      import java.util.function.Supplier;
      
      public class Test {
        static class A {
          private static String m() { return null; }
        }
        public static void main(String[] args) {
          Supplier<String> x  = A::m;
        }
      }
      

      Actual behaviour

      The compiler accepts the program, but I receive the following runtime error, because I access a private method.

      Exception in thread "main" java.lang.IllegalAccessError: class Test tried to access private method 'java.lang.String Test$A.m()' (Test and Test$A are in unnamed module of loader 'app')
              at Test.main(groovy51.groovy:9)
      

      Expected behavior

      The program should have been rejected by the compiler.

      Tested against master (commit: 191231a832efd2e2fc49391c01f8d176944d68e3)

      Attachments

        1. Test$A.class
          4 kB
          Thodoris Sotiropoulos
        2. Test.class
          3 kB
          Thodoris Sotiropoulos

        Issue Links

          Activity

            People

              emilles Eric Milles
              theosot Thodoris Sotiropoulos
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: