Eclipse JDT - How to set a breakpoint on an invisible default constructor?

How do I set a method entry breakpoint to a synthetic default constructor of a non-editable (library) class in eclipse Juno (4.2)?e.g.public class Foo {} // can't change that code// (...)...

How do I set a method entry breakpoint to a synthetic default constructor of a non-editable (library) class in eclipse Juno (4.2)?

e.g.

public class Foo {}  // can't change that code
//    (...)
Foo foo = new Foo()   // now it should stop
Foo bar = new Foo()  // stop again

Is it possible in general?

To further clarify this, I would like to stop every time an instance is of Foo is created at runtime, not once the class is loaded. In a complex setup, I have to distinguish if foo or bar is creating an instance.

It basically should be the same as a breakpoint on the invisible, synthetic constructor, without actually adding that constructor to the code, e.g.

public class Foo {
  public Foo(); //break here
}

Solved

For .class files, the default constructor is listed in the outline view. A method entry breakpoint can be added by right clicking on that.

For .class files, you can toggle a method entry breakpoint from the Outline view just as usual. For source files, you'll actually have to add such a constructor to set a breakpoint in it. The Outline View shows you what's in the file either way.

You can set the breakpoint on the line "public class Foo". If you normally double-click to set a breakpoint in the marker bar on the left side of the editor, then double click on the class declaration line.

I am possibly missing something but you could simply set a break point on the line Foo bar = new Foo(); and when the debugger stops there step into the code (so hit the F5 key).

If Foo extends any classes that actually implement a default constructor then your debugger will now be at the first super class in the hierarchy that has a default constructor.

If Foo doesn't extend any classes, or none of those have a default constructor, then you simply end up in the instantiation of Object.

If you have any member variables with initializers, then you can put a breakpoint on them. For example:

class MyClass {
  private int i = 0; // this line can have a breakpoint in Eclipse
}

Else see this question: How to set a breakpoint on a default Java constructor in Eclipse?

"#eclipse" helped solving it: The default constructor is shown in the outline view IF it's a .class file, not if it's a .java file. Then setting a method entry breakpoint is possible.

Translating... 0%