[ 
https://issues.apache.org/jira/browse/GROOVY-11301?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17812445#comment-17812445
 ] 

Thodoris Sotiropoulos commented on GROOVY-11301:
------------------------------------------------

{code}
❯ java -version
openjdk version "18-ea" 2022-03-15
OpenJDK Runtime Environment (build 18-ea+17-1015)
OpenJDK 64-Bit Server VM (build 18-ea+17-1015, mixed mode, sharing)
{code}

{code}
❯ groovy --compile-static program.groovy
Caught: 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 
groovy.lang.GroovyClassLoader$InnerLoader @85ec632)
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 
groovy.lang.GroovyClassLoader$InnerLoader @85ec632)
        at Test.main(program.groovy:8)
        at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at 
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at 
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
{code}

> References to inaccesible methods leads to runtime error
> --------------------------------------------------------
>
>                 Key: GROOVY-11301
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11301
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Priority: Minor
>
> I have the following ill-typed program
> {code}
> 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;
>   }
> }
> {code}
> h3. Actual behaviour
> The compiler accepts the program, but I receive the following runtime error, 
> because I access a private method.
> {code}
> 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)
> {code}
> h3. Expected behavior
> The program should have been rejected by the compiler.
> Tested against master (commit: 191231a832efd2e2fc49391c01f8d176944d68e3)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to