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.
Possibly also what Netbeans version?
Java 1.7 in IntelliJ doesn't show this, and steps into the super() call as expected.
At least with that info someone else may be able to test it on different IDE's.
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.
Check the bug report if you want to track this or upvote it.
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.