[Logo]
Forums Register Login
Initialized Class Variables Stop NetBeans Debugger from Stepping Into Explicit super() Call
I am stepping through the construction of a class that extends another class. Both have their own class variables. With no explicit call in the subclass constructor to super(), the NetBeans IDE debugger shows every step as I expect it to. That is, it steps through the superclass initialization of its own class variables, then its constructor code, then the subclass initialization of its class variables, then its constructor code. But, if I add an explicit call to super() in the subclass, the debugger never enters the superclass (unless I add a breakpoint in that class's code, in which case the debugger suspends when it hits that breakpoint). Further confusing things, the debugger does enter the superclass code if I include my explicit call to super(), but remove the subclass's class variables.

Here's my code:


This code exhibits the behavior I don't understand. If a breakpoint is set at Line 26 (the call to super() ), or at any prior point, stepping into each line does not step into the super() call, even though the superclass constructor and initiaization code does get executed. Commenting out the call to super() at line 26 results in the debugger stepping through the superclass constructor as expected. If, instead of commenting out the call to super(), I comment out the subclass member variable initialization at Line 22, the debugger once again does step through the superclass initialization code.

Can anyone explain why the presence of the explicit call to super() and the presence of the initialized member variables in the subclass together prevent the NetBeans debugger from descending into the expicit call to super(), while leaving either out results in the debugger stepping through the superclass initialization code (which is what one would expect)?

Note: I expect someone to ask me why I am making a no-argument call to super(), since leaving it out should make no difference to my code (since Java supplies the same call for me). The answer is that I'm not the one making the call, Swing is. In the no-argument constructor for JComboBox, there is a no-argument call to super(), which ought to have the debugger descend into the initialization code for JComboBox's parent class, JComponent. But it doesn't. My sample code, above, demonstrates the same behavior, which I am trying to understand. Thanks.

Don't know. Sorry. But I'll try duplicating this discussion in the IDEs forum.
Thanks. A better place.
What Java version is it?
Possibly also what Netbeans version?
Java 1.7 in IntelliJ doesn't show this, and steps into the super() call as expected.
I'm using NetBeans 8.0, JDK 1.8.0_05.
Of which I have neither...sorry.
At least with that info someone else may be able to test it on different IDE's.
Please update that JDK8 installation; it is out of date.
 

Campbell Ritchie wrote:Please update that JDK8 installation; it is out of date.


Done. (Doesn't affect the issue, but done.)
 

Stevens Miller wrote:I'm using NetBeans 8.0, JDK 1.8.0_05.


I can confirm the behavior. (JDK 1.8.0_20).

Looks like a bug in the debugger. Oh, the irony!
 

Darryl Burke wrote:Looks like a bug in the debugger. Oh, the irony!


Quite. I have filed a report at netbeans.org. It is Bug 247987, if anyone should care to vote.

Parallel question: Why would the JComboBox coder have used an explicit call to super()? Online comments I have found suggest it might be done to call special attention to the importance of a superclass's constructor to a particular subclass's behavior, but a comment would do that just as well (or even better). With further irony, some suggest it is a convenient place for a debugger breakpoint, but one can also just place that at the constructor's entry point. I've seen it discussed that maybe not every language automatically calls a superclass's constructor, but I doubt that ever applied to Java.

Any ideas?
(0 likes, 1 cow)
The good people at netbeans.org have found a workaround: use the "Step Into Next Method" operation, instead of "Step Into." There is no GUI button for that, so I didn't even know it existed. You can find it on the Debug menu, where you can also see that it is assigned to the "Shift F7" accelerator. I've tried it, and it works.

Check the bug report if you want to track this or upvote it.
Thank you for sharing the workaround here. That deserves a cow!
 

Darryl Burke wrote:Thank you for sharing the workaround here. That deserves a cow!


Thanks, Darryl! I'm happy to accept a cow, and will think of it as being earned equally by Martin Entlicher, who discovered the workaround in response to my bug report.
Don't MAKE me come back there with this tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA


This thread has been viewed 819 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jul 17, 2018 15:35:46.