Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.5.7, 2.5.8, 3.0.0-rc-1
-
None
Description
The following code works fine in 2.5.6 but breaks in 2.5.7 and 2.5.8:
GroovyShell shell = new GroovyShell() shell.evaluate(''' package a import groovy.transform.CompileStatic @CompileStatic abstract class Abstract_Class { protected String protectedField = 'field' abstract String doThing() } assert true''') shell.evaluate(''' package b import a.Abstract_Class import groovy.transform.CompileStatic @CompileStatic class ConcreteClass extends Abstract_Class { @Override String doThing() { 'something'.with { return protectedField } } } assert true''') shell.evaluate("assert new b.ConcreteClass().doThing() == 'field'")
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script2.groovy: 13: Access to a.Abstract_Class#protectedField is forbidden @ line 13, column 32. return protectedField ^
If you change both classes to be in the same package, you get a runtime error like this:
tried to access field a.Abstract_Class.protectedField from class a.ConcreteClass$_doThing_closure1 java.lang.IllegalAccessError: tried to access field a.Abstract_Class.protectedField from class a.ConcreteClass$_doThing_closure1
Attachments
Issue Links
- is related to
-
GROOVY-9292 Compilation error when accessing a protected super class field from a closure using owner, delegate or thisObject qualifier (different package)
- Closed
- links to