[
https://issues.apache.org/jira/browse/GROOVY-11301?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17820124#comment-17820124
]
Eric Milles commented on GROOVY-11301:
--------------------------------------
When I add nest mate(s) and nest host attributes, the error changes a bit:
{code}
IllegalAccessError: class Outer$$Lambda$89/0x0000000800166440 tried to access
private method Outer$Inner.m()Ljava/lang/String;
{code}
{code:groovy}
import groovy.transform.CompileStatic
import java.util.function.Supplier
@CompileStatic class Outer {
static class Inner {
private static String m() { 'works' }
}
static void test() {
Supplier<String> str = Inner::m
print str.get() // IllegalAccessError
}
}
Outer.test()
{code}
So it seems the nest attrs allow the access for nested elements. However, the
on-the-fly lambda class does not have the necessary attribute or the
ahead-of-time compiled class Outer is supposed to list the lambda class for
this to work. This may hint at why Java is creating the extra method.
> References to inaccesible methods with static compilation leads to runtime
> error
> --------------------------------------------------------------------------------
>
> Key: GROOVY-11301
> URL: https://issues.apache.org/jira/browse/GROOVY-11301
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation
> Reporter: Thodoris Sotiropoulos
> Priority: Minor
> Attachments: Test$A.class, Test.class
>
>
> 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)