[ https://issues.apache.org/jira/browse/GROOVY-7639?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14979764#comment-14979764 ]
ASF GitHub Bot commented on GROOVY-7639: ---------------------------------------- GitHub user shils opened a pull request: https://github.com/apache/incubator-groovy/pull/167 GROOVY-7639 Comparing primitive to null safe primitive property expre… …ssion should not throw NPE * Correct assertions in tests for GROOVY-5613 You can merge this pull request into a Git repository by running: $ git pull https://github.com/shils/incubator-groovy GROOVY-7639 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/incubator-groovy/pull/167.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 #167 ---- commit a6e380e3f96e61749f2dea5cec636a7c4bc28ca4 Author: Shil Sinha <sh...@apache.org> Date: 2015-10-29T03:58:56Z GROOVY-7639 Comparing primitive to null safe primitive property expression should not throw NPE * Correct assertions in tests for GROOVY-5613 ---- > 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 > > 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)