In Eclipse, I would like to set a breakpoint on a Java default constructor. I can't simply double click to the left of any line of code since default constructors have no source code - they are implicitly generated by the Java compiler.
I'd like to be able to set such a breakpoint without modifying the existing code.
First, set a breakpoint at a given location. Then, use the context menu on the breakpoint in the left editor margin or in the Breakpoints view in the Debug perspective, and select the breakpoint’s properties. In the dialog box, check Enable Condition, and enter an arbitrary Java condition, such as list.
Select all the methods using ctrl . Right click and select Toggle Method Breakpoint .
You can set a breakpoint on almost any line of code in a source file in the Definitions Pane, using either the "Toggle Breakpoint on Current Line" command in the Debugger menu, the "Toggle Breakpoint" command on the context (right-click) menu in the Definitions Pane, or by pressing Ctrl+B.
The debugger stops at main because a temporary breakpoint was set there. You don't see it because it evaporates as soon as it is hit. So, Eclipse IS setting breakpoints that work.
If the code where you want to set a breakpoint in, is on the build path and not in your project itself, then if you open the Outline view, you'll see that the default constructor is present there, and you can right-click on it and choose Toggle Method Breakpoint.
Note that sometimes the default constructor is filtered out of the Outline view. In that case it can be included by changing the filter settings. This is done by going to Outline view menu → Filters... → and unchecking Synthetic members.
This is in Eclipse Indigo, I don't know how long this functionality has been around.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With