You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (JIRA)" <ji...@apache.org> on 2019/04/18 18:35:00 UTC

[jira] [Commented] (GROOVY-9092) SC: IllegalAccessError for inner class access to outer class private field

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

Eric Milles commented on GROOVY-9092:
-------------------------------------

Sorry, this is not an issue for the current compiler.  GROOVY-9043 has more detail.

> SC: IllegalAccessError for inner class access to outer class private field
> --------------------------------------------------------------------------
>
>                 Key: GROOVY-9092
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9092
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.16, 3.0.0-alpha-4, 2.5.6
>            Reporter: Eric Milles
>            Priority: Major
>
> If GROOVY-9043 is fixed as indicated, the following cases fail at run-time with an IllegalAccessError.  Java allows an inner class (static and non-static) to read private fields of outer class(es).
> {code:groovy}
> @groovy.transform.CompileStatic class Outer {
>   private static final String CONST = 'value'
>   class Inner {
>     void meth() { print CONST } // IllegalAccessError: tried to access field Outer.CONST from class Outer$Inner
>   }
>   static main(args) {
>     new Inner(new Outer()).meth()
>   }
> }
> {code}
> {code:groovy}
> @groovy.transform.CompileStatic class Outer {
>   private static final String CONST = 'value'
>   static class Inner {
>     void meth() { print CONST } // IllegalAccessError: tried to access field Outer.CONST from class Outer$Inner
>   }
>   static main(args) {
>     new Inner().meth()
>   }
> }
> {code}
> Probably should also check that the non-static can access a non-static private field and that the static calss gets a compile-time error for the same thing.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)