You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Daniel Sun (Jira)" <ji...@apache.org> on 2020/05/07 22:56:00 UTC

[jira] [Resolved] (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 ]

Daniel Sun resolved GROOVY-9501.
--------------------------------
    Fix Version/s: 3.0.4
                   4.0.0-alpha-1
       Resolution: Fixed

> 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
>             Fix For: 4.0.0-alpha-1, 3.0.4
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> 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)