You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Aaron Zirbes (JIRA)" <ji...@apache.org> on 2015/10/19 18:53:05 UTC
[jira] [Commented] (GROOVY-7075) Safe Navigation operator does not
perform null check with @CompileStatic on interface type not declaring
getter
[ https://issues.apache.org/jira/browse/GROOVY-7075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14963595#comment-14963595 ]
Aaron Zirbes commented on GROOVY-7075:
--------------------------------------
This appears to still be an issue. I ran into it when using a Retrofit interface that returned an in with @CompileStatic in Groovy 2.4.5
> Safe Navigation operator does not perform null check with @CompileStatic on interface type not declaring getter
> ---------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-7075
> URL: https://issues.apache.org/jira/browse/GROOVY-7075
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation
> Affects Versions: 2.3.6
> Reporter: Jason Winnebeck
> Assignee: Cédric Champeau
> Priority: Critical
> Fix For: 2.3.7
>
>
> The following code produces NullPointerException when compiled static, but operates as expected when running in dynamic groovy:
> {code}
> import groovy.transform.CompileStatic
> @Grapes(
> @Grab(group='org.springframework.security', module='spring-security-core', version='3.2.5.RELEASE')
> )
> import org.springframework.security.core.context.SecurityContextHolder
> @CompileStatic
> def checkSafeNavi() {
> println SecurityContextHolder
> //class org.springframework.security.core.context.SecurityContextHolder
> println SecurityContextHolder.context
> //org.springframework.security.core.context.SecurityContextImpl@ffffffff: Null authentication
> println SecurityContextHolder.context?.authentication
> //null
> println SecurityContextHolder.context?.authentication?.name
> //NullPointerException
> }
> checkSafeNavi()
> {code}
> Thanks to Thibault Kruse for producing a minimal reproducible version.
> Here is another test case that doesn't use Spring Security or any other dependency. This hopefully should be able to be transformed directly into a unit test for Groovy:
> {code}
> //If Y was a class implementing YParent, it works
> //If Y had the getValue method directly, it works
> //If Y redeclares (overrides) getValue, it works
> interface Y extends YParent {
> }
> interface YParent {
> int getValue()
> }
> @groovy.transform.CompileStatic
> def check() {
> Y y = null
> println y?.value
> }
> check()
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)