Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.5.10
-
None
-
None
Description
Consider the following:
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() } } } }
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":
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)
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.