Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
Description
In some cases, the stack trace doesn't point to the source of error. Here is a case where the source of error is located properly:
def moo(Closure closure) {
closure.delegate = new Object()
closure.resolveStrategy = Closure.DELEGATE_ONLY
closure()
}
moo {
xyz
}
Exception in thread "main" groovy.lang.MissingPropertyException: No such property: xyz for class: java.lang.Object
... snip ...
at BindingDemo$_run_closure1.doCall(BindingDemo.groovy:8)
... snip ...
at BindingDemo.moo(BindingDemo.groovy:4)
... snip ...
at BindingDemo.run(BindingDemo.groovy:7)
... snip ...
BindingDemo.groovy:7 is the closure containing the error, BindingDemo.groovy:4 is where I call the problem closure and BindingDemo.groovy:8 is the line where the error is located (ie. missing property exception). Awesome.
Now try the same thing except with assignment:
def moo(Closure closure) {
closure.delegate = new Object()
closure.resolveStrategy = Closure.DELEGATE_ONLY
closure()
}
moo {
xyz = 1
}
Exception in thread "main" groovy.lang.MissingPropertyException: No such property: xyz for class: java.lang.Object
... snip ...
at BindingDemo.moo(BindingDemo.groovy:4)
... snip ...
at BindingDemo.run(BindingDemo.groovy:7)
... snip ...
This gives the same stack trace except BindingDemo.groovy:8 is missing.
Getting a line number for a the error is a useful diagnostic to have and the first case demonstrates that this is possible.