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 2020/04/26 16:34:00 UTC
[jira] [Assigned] (GROOVY-9501) MissingPropertyException for access
to private static field from inner class when subclassing
[ https://issues.apache.org/jira/browse/GROOVY-9501?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles reassigned GROOVY-9501:
-----------------------------------
Assignee: Eric Milles
> MissingPropertyException for access to private static field from inner class when subclassing
> ---------------------------------------------------------------------------------------------
>
> Key: GROOVY-9501
> URL: https://issues.apache.org/jira/browse/GROOVY-9501
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 2.5.10
> Reporter: Eric Milles
> Assignee: Eric Milles
> Priority: Major
>
> Consider the following:
> {code:groovy}
> class Main extends Outer {
> static main(args) {
> newInstance().newThread()
> }
> }
> abstract class Outer {
> private static volatile boolean flag
> protected void newThread() {
> Thread thread = new Inner()
> thread.start()
> thread.join()
> }
> private final class Inner extends Thread {
> void run() {
> try {
> if (!flag) {
> sleep(1000)
> }
> } catch (Throwable t) {
> t.printStackTrace()
> }
> }
> }
> }
> {code}
> In this example, {{Main}} extends {{Outer}} and is the type that is instantiated and used. {{Inner}} makes reference to private static field {{flag}} of {{Outer}}. When {{Inner}} is non-static as in this example, it gets the following error when reading "flag":
> {code}
> groovy.lang.MissingPropertyException: No such property: flag for class: Main
> Possible solutions: class
> at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:65)
> at org.codehaus.groovy.runtime.callsite.GetEffectivePogoPropertySite.getProperty(GetEffectivePogoPropertySite.java:87)
> at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:309)
> at Outer$Inner.run(Script1.groovy:20)
> {code}
> *Note*: changing {{Inner}} from final to static fixes this specific case. However, non-static inners that need to be that way are going to have this problem.
> This is possibly related to: GROOVY-8999, et al.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)