forked from ringcentral/spock
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NPE when variable is initialized using a method with the same name in features calling "thrown()" #1266
Comments
Hm, this might be a bit tricky to fix. This happens because Spock transforms the java.lang.Object foo
this.getSpecificationContext().setThrownException(null)
try {
foo = foo.call()
this.println(foo)
throw new java.lang.IllegalStateException()
}
catch (java.lang.Throwable $spock_ex) {
this.getSpecificationContext().setThrownException($spock_ex)
} as you can see declaration and assignment are now split. It is basically the same as class Other {
void bar() {
def foo = null
foo = foo() // fails here
}
String foo() {
return "foo"
}
} I'm pretty sure that is some groovy heuristic that turns |
leonard84
referenced
this issue
in leonard84/spock
Apr 23, 2021
in features with cleanup blocks or using thrown condition fixes #1266, fixes #1313
leonard84
added a commit
that referenced
this issue
Apr 23, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue description
A variable initialized using a method with the same name, as in
def foo = foo()
throws aNullPointerException
when used in a feature method that callsthrown()
inthen:
block.How to reproduce
foo test
fails when running this test class (only tried with Gradle):Additional Environment information
Java/JDK
java -version
Build-tool dependencies used
Gradle 6.8.1
Fails with:
testImplementation("org.spockframework:spock-core:2.0-M4-groovy-2.5")
andtestImplementation("org.spockframework:spock-core:2.0-M4-groovy-3.0")
Works with:
testImplementation("org.spockframework:spock-core:1.3-groovy-2.5")
The text was updated successfully, but these errors were encountered: