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 2022/04/28 16:43:00 UTC

[jira] [Commented] (GROOVY-10606) Access to private static fields in inherited methods doesn't work in Groovy 4

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

Eric Milles commented on GROOVY-10606:
--------------------------------------

Static compilation will generate the necessary bridge for accessing this private field from subclass.  Or qualifying the name might work as well.  Static member "inheritance" needed to be adjusted in the meta class index to fix other issues.

> Access to private static fields in inherited methods doesn't work in Groovy 4
> -----------------------------------------------------------------------------
>
>                 Key: GROOVY-10606
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10606
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 4.0.2
>            Reporter: Leonard Brünings
>            Priority: Major
>
> {code:groovy}
> class Reproducer {
>     private static final String PREFIX = 'prop.'
>        
>     
>     static void main(String... args) {
>     	new Reproducer().doTheThing()
>     	new Child().doTheThing()
>     }
>     
>     void doTheThing() {
>         def map = [a: 'A', b:'B']
>         
>         map.forEach( (key, value) -> {
>             println PREFIX + key + " $value"
>         })
>     }
>     
> }
> class Child extends Reproducer {
>     
> }
> {code}
> ([Groovy Web Console|https://gwc-experiment.appspot.com/?g=groovy_4_0&codez=eJxtkVFLwzAUhZ_trzgMISmb-QEDBR0b7E3mHgTxISa3a1iWljSrivS_m8XadbD7cAnc7-TcnCgrmwYbqn2lj4o8fjLEqr1pZSA0QQajUBgnLV6CN26H581ytX7FPVgU1YIlQaxsaL2qrYzGQRrH_5RCCEi_a_Le5MbR58ia50JX25K2ZWR5fkYWpbH62rQ7WyavMdB7nEpTEdeo48Zvcg72yGb4mLMn9j4QwyFioqj8UqqSg-_pe4ZW2iPluHsY3dhH5IJ1_3FMEenYJ7hNiskAdxfLdlmmUubpVaCvQE5f-YETOLb7BQlGcZw])
> Works in Groovy 2.5.x and 3.x but fails with Groovy 4.0.2 
> {noformat}
> groovy.lang.MissingPropertyException: No such property: PREFIX for class: Child
> 	at Reproducer$_doTheThing_closure1.doCall(Script1.groovy:14)
> 	at com.sun.proxy.$Proxy21.accept(Unknown Source)
> 	at Reproducer.doTheThing(Script1.groovy:13)
> 	at Reproducer.main(Script1.groovy:7)
> {noformat}



--
This message was sent by Atlassian Jira
(v8.20.7#820007)