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 17:28:00 UTC

[jira] [Comment Edited] (GROOVY-9043) Access to package-scoped static field is forbidden for inner class in static compilation mode

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

Eric Milles edited comment on GROOVY-9043 at 4/18/19 5:27 PM:
--------------------------------------------------------------

If access to private fields is allowed from inner classes, an IllegalAccessError is thrown at run-time.  Java allows this, so there must be some bridge or something going on there.

{code:java}
public class Java9043 {
  private static final String CONST = "value";

  public static void main(String[] args) {
    new Java9043().new Inner().meth();
  }

  class Inner {
    void meth() {
      System.out.println(CONST);
    }
  }
}
{code}

This prints "value" as expected.


was (Author: emilles):
If access to private fields is allowed from inner classes, an IllegalAccessError is thrown at run-time.  Java allows this, so there must be some bridge or something going on there.

{code:java}
public class Java9043 {
  private static final String CONST = "value"; //$NON-NLS-1$

  public static void main(String[] args) {
    new Java9043().new Inner().meth();
  }

  class Inner {
    void meth() {
      System.out.println(CONST);
    }
  }
}
{code}

This prints "value" as expected.

> Access to package-scoped static field is forbidden for inner class in static compilation mode
> ---------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-9043
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9043
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 3.0.0-alpha-4, 2.5.6
>            Reporter: Basil Peace
>            Priority: Minor
>
> Given:
>  
> {code:java}
> import groovy.transform.CompileStatic
> import groovy.transform.PackageScope
> @CompileStatic
> class Test {
>   @PackageScope
>   static final String S = 'Some constant'
>   static class Inner {
>     String method() {
>       S
>     }
>   }
> }
> {code}
> there is a compilation error:
>  
>  
> {noformat}
> Access to Test#S is forbidden @ line -1, column -1.{noformat}
> No error without @CompileStatic.
>  
> Analogous code works in Java



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