groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jochen Theodorou (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8938) Final field caching issues in inherited field.
Date Tue, 25 Dec 2018 11:27:00 GMT

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

Jochen Theodorou commented on GROOVY-8938:
------------------------------------------

[~anton.pryamostanov] why is it "final", because we once said all modifiers that on the "property"
should be applied to the getter/setter if possible. But it is indeed a question of it that
should be done for final. Following the logic of a field I would say the getter should not
be final. But I think that will start breaking things in other cases like @Immutable? If we
keep the final on the method we should fail compilation in your example though... but then
how would you work around it? By declaring it as field. If you declare it as field, then what
will
assert subClass.inheritedField.toString() == "Sub Class String"
give you? Afair you would still access the super class and get still a failing assert. And
of course you could do,
assert subClass.@inheritedField.toString() == "Sub Class String"
but that would work already. 

 

Coming back to your suggestion it looks like a good idea, but it will make declaring immutables
much more difficult. So before we do a change here I would suggest to first ensure the story
for these is sound.

 

> Final field caching issues in inherited field.
> ----------------------------------------------
>
>                 Key: GROOVY-8938
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8938
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.5.4
>            Reporter: Anton Pryamostanov
>            Priority: Critical
>
> Note: **this seems to be a quite major issue**, kindly look at this one with emphasis.
> Please see the below test case:
> SubClass extends the SuperClass and overrides the field "inheritedField".
> {code}
> class OtherClass {
>     String otherField
>     OtherClass(String otherField) {
>         this.otherField = otherField
>     }
>     String toString() {
>         return otherField
>     }
> }
> class SuperClass {
>     final OtherClass inheritedField = new OtherClass("Super Class String")
> }
> class SubClass extends SuperClass {
>     final OtherClass inheritedField = new OtherClass("Sub Class String")
> }
> SuperClass superClass = new SuperClass()
> SubClass subClass = new SubClass()
> assert subClass.inheritedField.toString() == "Sub Class String"
> {code}
> *Actual result*: assertion fails
> *Expected result*: assertion should pass
> *Note*: If "final" modifier is removed, assertion passes as expected.
> This seems an issue with final field caching.
> Assertion error text:
> {code}
> Assertion failed: 
> assert subClass.inheritedField.toString() == "Sub Class String"
>        |        |              |          |
>        |        |              |          false
>        |        |              'Super Class String'
>        |        Super Class String
>        SubClass@5b4b841f
> 	at ConsoleScript11.run(ConsoleScript11:18)
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message