Closed matifreyre closed 8 years ago
I just edited the previous comment: the closure in the first piece of code should have a parameter. The issue remains valid, though.
Cool. This kind of bad cause reporting for errors are priority.
+1
On Thu, Jan 7, 2016 at 3:48 PM, javierfernandes notifications@github.com wrote:
Cool. This kind of bad cause reporting for errors are priority.
— Reply to this email directly or view it on GitHub https://github.com/uqbar-project/wollok/issues/578#issuecomment-169770710 .
Ok. So, there are two problems here. The underlying cause of both problems is indeed a null pointer. When trying to send a message to something that evaluates to "null". Eventually we might want to analyse the change to model "null" as a wollok object. I just didn't want to get into that change, because it affects many places.
So, in the first case it is showing a "wollok exception", that's good. We always want to see that kind fo stack trace and not the java stack trace as it is the case in the second example.
The problem with the first case is that the wollok stack trace doesn't include the real cause: you cannot send a message to null. So I have improved that. Now this test
object link {
var arma
method atacarA(alguien) {
arma.causarDanio(alguien)
}
}
object captainFalcon {}
test "testX" {
#{ 1 }.forEach({ each => link.atacarA(captainFalcon) })
}
Fails like this
wollok.lang.Exception: Error while calling native method 'WCollection.fold(WollokObject, WollokObject) with parameters: null, aClosure(acc, e)
at wollok.lang.Set.fold(initialValue,closure) [/wollok.wlk:365]
at wollok.lang.Collection.forEach(closure) [/wollok.wlk:231]
at [/nullpointer.wtest:13]
Caused by: wollok.lang.Exception: Error while calling native method 'Closure.doApply(WollokObject[]) with parameters: [Lorg.uqbar.project.wollok.interpreter.core.WollokObject;@5d1e09bc
at wollok.lang.Closure.apply(parameters) [/wollok.wlk:604]
at wollok.lang.Collection.forEach(closure) [/wollok.wlk:231]
at wollok.lang.Set.fold(initialValue,closure) [/wollok.wlk:365]
at wollok.lang.Collection.forEach(closure) [/wollok.wlk:231]
at [/nullpointer.wtest:13]
Caused by: wollok.lang.Exception: Cannot send message causarDanio(alguien) to null
at nullpointer.link.atacarA(alguien) [/nullpointer.wtest:5]
at [/nullpointer.wtest:9]
at wollok.lang.Closure.apply(parameters) [/wollok.wlk:604]
at wollok.lang.Collection.forEach(closure) [/wollok.wlk:231]
at wollok.lang.Set.fold(initialValue,closure) [/wollok.wlk:365]
at wollok.lang.Collection.forEach(closure) [/wollok.wlk:231]
at [/nullpointer.wtest:13]
I wonder if we can just remove the intermediate exceptions being automatically generated for native methods. But I'm afraid we will lose information for other exceptions.
Now as the NPE triggers a wollok exception throwing (and not java) the second case got solved
test "testX" {
link.atacarA(captainFalcon)
}
Causes
wollok.lang.Exception: Cannot send message causarDanio(alguien) to null
at nullpointer.link.atacarA(alguien) [/nullpointer.wtest:5]
at [/nullpointer.wtest:9]
This code raises an exception due to "link" not having a weapon (variable
arma
is null), which is used within the method atacarA:The stack trace obtained from the exception is the following:
As it can be seen, the stack trace only informs that the closure could not be evaluated, but not why.
If I simply write the content of the closure instead (
link.atacarA(captainFalcon)
), the stack trace changes. It can be seen that the problem is ajava.lang.NullPointerException
caused byarma.poderPara(this)
: