Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.3.0-beta-1
-
None
-
None
Description
While upgrading Grails to use Groovy 2.3.0-beta-1 I came across a scenario where a NullPointerException is being thrown in a scenario where I don't think it should be. It seems that the null safety operator isn't working as it should.
I have attached a simple sample app with the following code. Running the test yields a NullPointerException.
./gradlew test
src/main/groovy/com/demo/Widget.groovy
package com.demo @groovy.transform.CompileStatic class Widget { def isValid(Map m) { boolean isValid = true def dir = m.dir?.toString() def file = m.file?.toString() if(file) { if (!(file.startsWith('/') || dir?.endsWith('/'))) { isValid = false } } isValid } }
src/test/groovy/com/demo/WidgetSpec.groovy
package com.demo import spock.lang.Specification class WidgetSpec extends Specification { void 'test with file and no dir'() { when: def widget = new Widget() def m = [file: 'someFile'] then: !widget.isValid(m) } }