Debugger -> View "this" as toString(): throws NPE when debugging constructor

When debugging the constructor code (see screenshot attached) - having toString() view for "this" throws a NullPointerException. Now, I didn't turn on this toString() view explicitly - it was left when I watched instances of this class on other occasions and in other places.

I think "this" debug window shouldn't attempt a toString() view when inside class constructor.

5 comments
Comment actions Permalink

Whoops, here goes the screenshot



Attachment(s):
1.gif
0
Comment actions Permalink

And another one



Attachment(s):
2.gif
0
Comment actions Permalink

I think "this" debug window shouldn't attempt a toString() view when inside class constructor.


Why not?
For this particular class - perhaps it shouldn't. But this may work ok for other clases. In general, every method invocation
performed by debugger can lead to deadlock or exception when method is invoked at improper moment. Following the logic, debugger
should not try to perform any method invocations at all.


--
Best regards,
Eugene Zhuravlev
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0
Comment actions Permalink

every method invocation performed by debugger can lead to deadlock or exception when method is invoked at improper moment

Do you mean methods invoked explicitly by the user when he evaluates some expression ? If yes, you're correct, but since method is invoked by the user - he knows some Exception may be thrown (and, in fact, it happens quite a lot when I play in "Evaluate Expression" window)
toString() method invoked implicitly (almost, because user checked this option someday) on "this" and throwing an Exception just because user happend to stop in constructor - I see it as completely another and, frankly, unexpected behaviour. After all, the instance isn't created yet so it doesn't make any sence to implicitly invoke any methods on it.

0
Comment actions Permalink

Do you mean methods invoked explicitly by the user when he evaluates some expression ? If yes, you're correct, but since
method is invoked by the user - he knows some Exception


I meant "alternate Collection Views", "toString()" and "Type Renderers" as well. These features all call methods on object
instances.
As for calling calling methods implicitly: well, they are called after you explicitly turned the option on.

it as completely another and, frankly, unexpected behaviour. After all, the instance isn't created yet so it doesn't make any
sence to implicitly invoke any methods on it.


if the instance is initialized enough for toString() to produce meaningful result - it makes sence.


--
Best regards,
Eugene Zhuravlev
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0

Please sign in to leave a comment.