Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.3.0
-
None
Description
When using @CompileStatic and an elvis operator unexpected NullPointerExceptions are thrown. Here is an example script to recreate the issue.
package my.company @Grab(group='org.codehaus.groovy', module='groovy-all', version='2.1.6') import groovy.transform.CompileStatic @CompileStatic class Outer { public static void main(String[] args) { Inner inner int someInt = inner?.somestuff ?: 0 println someInt } class Inner { int somestuff } }
You would expect this to print 0 always, but if @CompileStatic is used a NPE is thrown. Without @CompileStatic 0 is printed as expected.