You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2020/11/11 02:01:04 UTC
[jira] [Closed] (GROOVY-7165) Static Compilation: private static
field accessed from a Closure produces a runtime error
[ https://issues.apache.org/jira/browse/GROOVY-7165?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King closed GROOVY-7165.
-----------------------------
> 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<String> staticfield = new ArrayList<>()
> void show()
> {
> List<Function<List<String>, String>> runners = new ArrayList<>()
> runners.add(new Called())
> List<String> cmds = ["hello"]
> runners.each { cmds.addAll(it.apply(staticfield)) }
> println cmds.size()
> }
> class Called implements Function<List<String>, String>
> {
> @Override
> String apply(List<String> strings) {
> "groovin"
> }
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)