[jira] [Commented] (GROOVY-7165) Static Compilation: private static field accessed from a Closure produces a runtime error

2018-09-21 Thread Eric Milles (JIRA)


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

Eric Milles commented on GROOVY-7165:
-

Any chance of getting this fixed for 2.4.x and 2.5.3?  Whether or not private 
field access should be allowed is a topic for 3+.  As indicated, private field 
access does work in many cases.  And so I would expect that moving from 
"Type.VALUE" to "import static Type.VALUE" paired with "VALUE" should work as 
well.

> Static Compilation: private static field accessed from a Closure produces a 
> runtime error
> -
>
> Key: GROOVY-7165
> URL: https://issues.apache.org/jira/browse/GROOVY-7165
> Project: Groovy
>  Issue Type: Bug
>  Components: Static compilation
>Affects Versions: 2.3.7
>Reporter: Neil Galarneau
>Priority: Major
>
> The following code compiles cleanly but throws an exception at runtime.
> This code doesn't have a stack trace. The code I simplified this from, did 
> have a stack trace.
> If I remove 'private' from staticfield, then it works:
> {code}
> @CompileStatic
> class TestPrivateStaticFieldInClosure extends BaseBug
> {
>   public static void main(String[] args)
>   {
> (new TestPrivateStaticFieldInClosure()).show()
>   }
> }
> @CompileStatic
> class BaseBug
> {
>   private static ArrayList staticfield = new ArrayList<>()
>   void show()
>   {
> List, String>> runners = new ArrayList<>()
> runners.add(new Called())
> List cmds = ["hello"]
> runners.each { cmds.addAll(it.apply(staticfield)) }
> println cmds.size()
>   }
>   class Called implements Function, String>
>   {
> @Override
> String apply(List strings) {
>   "groovin"
> }
>   }
> }
> {code}



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


[jira] [Commented] (GROOVY-7165) Static Compilation: private static field accessed from a Closure produces a runtime error

2018-09-07 Thread Daniel Sun (JIRA)


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

Daniel Sun commented on GROOVY-7165:


We should forbidden accessing `private` members from other classes.

{code:java}
class Base {

  private static final String CONST = 'const'

}

class C extends Base {

  static main(args) {

println Base.CONST // I expect some error here

println CONST // throws MissingPropertyException

  }

}
{code}

> Static Compilation: private static field accessed from a Closure produces a 
> runtime error
> -
>
> Key: GROOVY-7165
> URL: https://issues.apache.org/jira/browse/GROOVY-7165
> Project: Groovy
>  Issue Type: Bug
>  Components: Static compilation
>Affects Versions: 2.3.7
>Reporter: Neil Galarneau
>Priority: Major
>
> The following code compiles cleanly but throws an exception at runtime.
> This code doesn't have a stack trace. The code I simplified this from, did 
> have a stack trace.
> If I remove 'private' from staticfield, then it works:
> {code}
> @CompileStatic
> class TestPrivateStaticFieldInClosure extends BaseBug
> {
>   public static void main(String[] args)
>   {
> (new TestPrivateStaticFieldInClosure()).show()
>   }
> }
> @CompileStatic
> class BaseBug
> {
>   private static ArrayList staticfield = new ArrayList<>()
>   void show()
>   {
> List, String>> runners = new ArrayList<>()
> runners.add(new Called())
> List cmds = ["hello"]
> runners.each { cmds.addAll(it.apply(staticfield)) }
> println cmds.size()
>   }
>   class Called implements Function, String>
>   {
> @Override
> String apply(List strings) {
>   "groovin"
> }
>   }
> }
> {code}



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


[jira] [Commented] (GROOVY-7165) Static Compilation: private static field accessed from a Closure produces a runtime error

2018-09-07 Thread Eric Milles (JIRA)


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

Eric Milles commented on GROOVY-7165:
-

I have seen the same with static final fields.  Strangely, the implicit-this 
case fails but the class expression qualifier works just fine.  So it is not 
that Groovy says no to accessing private members.  It just is failing to 
resolve to super types for private static fields.

{code:groovy}

class Base {

  private static final String CONST = 'const'

}

class C extends Base {

  static main(args) {

    println Base.CONST // works

    println CONST // throws MissingPropertyException

  }

}
{code}

> Static Compilation: private static field accessed from a Closure produces a 
> runtime error
> -
>
> Key: GROOVY-7165
> URL: https://issues.apache.org/jira/browse/GROOVY-7165
> Project: Groovy
>  Issue Type: Bug
>  Components: Static compilation
>Affects Versions: 2.3.7
>Reporter: Neil Galarneau
>Priority: Major
>
> The following code compiles cleanly but throws an exception at runtime.
> This code doesn't have a stack trace. The code I simplified this from, did 
> have a stack trace.
> If I remove 'private' from staticfield, then it works:
> {code}
> @CompileStatic
> class TestPrivateStaticFieldInClosure extends BaseBug
> {
>   public static void main(String[] args)
>   {
> (new TestPrivateStaticFieldInClosure()).show()
>   }
> }
> @CompileStatic
> class BaseBug
> {
>   private static ArrayList staticfield = new ArrayList<>()
>   void show()
>   {
> List, String>> runners = new ArrayList<>()
> runners.add(new Called())
> List cmds = ["hello"]
> runners.each { cmds.addAll(it.apply(staticfield)) }
> println cmds.size()
>   }
>   class Called implements Function, String>
>   {
> @Override
> String apply(List strings) {
>   "groovin"
> }
>   }
> }
> {code}



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