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 2015/11/02 21:55:27 UTC

[jira] [Resolved] (GROOVY-7639) NPE when using safe traversal operator with CompileStatic

     [ https://issues.apache.org/jira/browse/GROOVY-7639?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jochen Theodorou resolved GROOVY-7639.
--------------------------------------
       Resolution: Fixed
         Assignee: Shil Sinha
    Fix Version/s: 2.4.6

I resolve the issue for you.... I added some permissions for you, so you should be able to do it yourself next time

> NPE when using safe traversal operator with CompileStatic
> ---------------------------------------------------------
>
>                 Key: GROOVY-7639
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7639
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 2.4.5
>            Reporter: Ben Podoll
>            Assignee: Shil Sinha
>             Fix For: 2.4.6
>
>
> In the code below, the "if" condition throws a NPE when it reaches the "p3" object. If I remove the @CompileStatic from the "SomeOther" class it works.
> {code:java}
> import groovy.transform.CompileStatic
> @CompileStatic
> class Person {
>   String name
>   OtherInfo otherInfo
> }
> @CompileStatic
> class OtherInfo {
>   int favoriteNumber
> }
> @CompileStatic
> class SomeOther {
>   SomeOther() {
>     Person p1 = new Person(name: 'Ben', otherInfo: new OtherInfo(favoriteNumber: 1))
>     Person p2 = new Person(name: 'Aaron', otherInfo: new OtherInfo())
>     Person p3 = new Person(name: 'Fred')
>     [p1,p2,p3].each { Person p ->
>       println "checking: ${p.name}"
>       println p?.otherInfo?.favoriteNumber
>       if(p?.otherInfo?.favoriteNumber == 7){
>         println "luckiest number!"
>       }
>     }
>   }
> }
> new SomeOther()
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)