groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Milles (Jira)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-9288) Compilation error when accessing a protected/public/package-private super class field from inside a closure
Date Sun, 27 Oct 2019 15:56:00 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-9288?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16960633#comment-16960633
] 

Eric Milles commented on GROOVY-9288:
-------------------------------------

As I noted in the pull request, I have tried out a few things to gain some understanding.
 I have added several test cases from linked bugs and some others that were fixed after GROOVY-7996
and GROOVY-9007.  I think the best course of action is to not patch the delegate/owner SC
fix one more time and instead roll it back.  This was completed on master and my own testing
showed this issue to be resolved as well as the use of "owner" and "thisObject" qualifiers
(tests added).

> Compilation error when accessing a protected/public/package-private super class field
from inside a closure
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-9288
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9288
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.5.7, 2.5.8, 3.0.0-rc-1
>            Reporter: John Bellassai
>            Priority: Major
>             Fix For: 2.5.9, 3.0.0-rc-2
>
>          Time Spent: 2h
>  Remaining Estimate: 0h
>
> The following code works fine in 2.5.6 but breaks in 2.5.7 and 2.5.8:
> {code:java}
> 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'")
> {code}
> {noformat}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> Script2.groovy: 13: Access to a.Abstract_Class#protectedField is forbidden @ line 13,
column 32.
>                            return protectedField
>                                   ^
> {noformat}
> If you change both classes to be in the same package, you get a runtime error like this:
> {noformat}
> 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
> {noformat}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Mime
View raw message