You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Jochen Theodorou (JIRA)" <ji...@apache.org> on 2018/09/27 12:29:06 UTC

[jira] [Commented] (GROOVY-8811) Groovy should fail compilation when assigning final fields to themselves

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

Jochen Theodorou commented on GROOVY-8811:
------------------------------------------

well.. my suggestion is to do this check not only for final, but in general. Its a nice to have

> Groovy should fail compilation when assigning final fields to themselves
> ------------------------------------------------------------------------
>
>                 Key: GROOVY-8811
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8811
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.5.2
>            Reporter: Graeme Rocher
>            Priority: Major
>
> It is possible in Groovy to assign a final field to itself with the result ending up being null. This leads to hard to debug problems:
>  
> {code:java}
> class LoadedVisitor {
>     private final SourceUnit sourceUnit
>     LoadedVisitor( SourceUnit source) {
>         this.sourceUnit = sourceUnit; // assign to self
>    }
> } 
> {code}
> The above example will result in `sourceUnit` being `null`
> This should be a compilation error to avoid confusing problems as it is in Java.



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