-
Notifications
You must be signed in to change notification settings - Fork 480
Closed
Description
Issue description
A variable initialized using a method with the same name, as in def foo = foo() throws a NullPointerException when used in a feature method that calls thrown() in then: block.
How to reproduce
class SomeSpec extends spock.lang.Specification {
def "foo test"() { // fails
when:
def foo = foo() // fails here
println(foo)
throw new IllegalStateException()
then:
thrown IllegalStateException
}
def "bar test"() { // passes
when:
def bar = foo()
println(bar)
throw new IllegalStateException()
then:
thrown IllegalStateException
}
String foo() {
return "foo"
}
}
foo test fails when running this test class (only tried with Gradle):
Expected exception of type 'java.lang.IllegalStateException', but got 'java.lang.NullPointerException'
at org.spockframework.lang.SpecInternals.checkExceptionThrown(SpecInternals.java:81)
at org.spockframework.lang.SpecInternals.thrownImpl(SpecInternals.java:68)
at SomeSpec.foo test(SomeSpec.groovy:9)
Caused by: java.lang.NullPointerException: Cannot invoke method call() on null object
at SomeSpec.foo test(SomeSpec.groovy:4)
Additional Environment information
Java/JDK
java -version
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.8+10, mixed mode)
Build-tool dependencies used
Gradle 6.8.1
Fails with: testImplementation("org.spockframework:spock-core:2.0-M4-groovy-2.5") and testImplementation("org.spockframework:spock-core:2.0-M4-groovy-3.0")
Works with: testImplementation("org.spockframework:spock-core:1.3-groovy-2.5")
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels