[jira] [Commented] (GROOVY-8281) Final field is null in trait, but it has assigned value

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (GROOVY-8281) Final field is null in trait, but it has assigned value

JIRA jira@apache.org

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

ASF GitHub Bot commented on GROOVY-8281:
----------------------------------------

GitHub user paulk-asert opened a pull request:

    https://github.com/apache/groovy/pull/772

    GROOVY-8281: Final field is null in trait, but it has assigned value

   

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/paulk-asert/groovy groovy8281

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/groovy/pull/772.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #772
   
----
commit be7834c73ff967372f7714bad3ec1c5b662d1456
Author: Paul King <paulk@...>
Date:   2018-07-10T11:51:57Z

    GROOVY-8281: Final field is null in trait, but it has assigned value

----


> Final field is null in trait, but it has assigned value
> -------------------------------------------------------
>
>                 Key: GROOVY-8281
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8281
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.8, 2.4.9, 2.4.10, 2.4.11, 2.4.12
>            Reporter: Dominik Przybysz
>            Priority: Major
>
> I have a code like this:
> {code}
> trait MyTrait {
> final String myValue = "test"
> final Wrapper wrapper = new Wrapper(myValue)
> }
> class Wrapper {
> Wrapper(String value){
> if(value == null) {
> throw new Exception("Value is null!!!")
> }
> println "OK: $value"
> }
> }
> class Main implements MyTrait {}
> new Main()
> {code}
> Everything works as expected with groovy 2.4.7:
> {code}
> $ sdk u groovy 2.4.7
> Using groovy version 2.4.7 in this shell.
> $ groovy bug.groovy
> OK: test
> {code}
> but newer versions of groovy do not compile this code (2.4.8, 2.4.9, 2.4.10) or have null to value (2.4.11, 2.4.12):
> {code}
> $ sdk u groovy 2.4.8
> Using groovy version 2.4.8 in this shell.
> $ groovy bug.groovy
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> ~/bug.groovy: 3: Apparent variable 'myValue' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:
> You attempted to reference a variable in the binding or an instance variable from a static context.
> You misspelled a classname or statically imported field. Please check the spelling.
> You attempted to use a method 'myValue' but left out brackets in a place not allowed by the grammar.
>  @ line 3, column 38.
>     final Wrapper wrapper = new Wrapper(myValue)
>                                         ^
> 1 error
> $ sdk u groovy 2.4.9
> Using groovy version 2.4.9 in this shell.
> $ groovy bug.groovy
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> ~/bug.groovy: 3: Apparent variable 'myValue' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:
> You attempted to reference a variable in the binding or an instance variable from a static context.
> You misspelled a classname or statically imported field. Please check the spelling.
> You attempted to use a method 'myValue' but left out brackets in a place not allowed by the grammar.
>  @ line 3, column 38.
>     final Wrapper wrapper = new Wrapper(myValue)
>                                         ^
> ~/bug.groovy: 3: Apparent variable 'myValue' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:
> You attempted to reference a variable in the binding or an instance variable from a static context.
> You misspelled a classname or statically imported field. Please check the spelling.
> You attempted to use a method 'myValue' but left out brackets in a place not allowed by the grammar.
>  @ line 3, column 38.
>     final Wrapper wrapper = new Wrapper(myValue)
>                                         ^
> 2 errors
> $ sdk u groovy 2.4.10
> Using groovy version 2.4.10 in this shell.
> $ groovy bug.groovy
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> ~/bug.groovy: 3: Apparent variable 'myValue' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:
> You attempted to reference a variable in the binding or an instance variable from a static context.
> You misspelled a classname or statically imported field. Please check the spelling.
> You attempted to use a method 'myValue' but left out brackets in a place not allowed by the grammar.
>  @ line 3, column 38.
>     final Wrapper wrapper = new Wrapper(myValue)
>                                         ^
> ~/bug.groovy: 3: Apparent variable 'myValue' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:
> You attempted to reference a variable in the binding or an instance variable from a static context.
> You misspelled a classname or statically imported field. Please check the spelling.
> You attempted to use a method 'myValue' but left out brackets in a place not allowed by the grammar.
>  @ line 3, column 38.
>     final Wrapper wrapper = new Wrapper(myValue)
>                                         ^
> 2 errors
> $ sdk u groovy 2.4.11
> Using groovy version 2.4.11 in this shell.
> $ groovy bug.groovy
> Caught: java.lang.Exception: Value is null!!!
> java.lang.Exception: Value is null!!!
> at Wrapper.<init>(bug.groovy:9)
> at MyTrait$Trait$Helper.$init$(bug.groovy:3)
> at Main.<init>(bug.groovy)
> at bug.run(bug.groovy:17)
> $ sdk u groovy 2.4.12
> Using groovy version 2.4.12 in this shell.
> $ groovy bug.groovy
> Caught: java.lang.Exception: Value is null!!!
> java.lang.Exception: Value is null!!!
> at Wrapper.<init>(bug.groovy:9)
> at MyTrait$Trait$Helper.$init$(bug.groovy:3)
> at Main.<init>(bug.groovy)
> at bug.run(bug.groovy:17)
> {code}



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