Why can't I set breakpoints in some constructors?

Eric Rizzo

VAJ generally supports setting breakpoints in constructors, but there are some situations where it will refuse to set a constructor breakpoint on the exact line you want, or even at all.
The most common code situation that causes this behavior is one or more of the class's instance variables are initialized at their declaration, such as this:

public class Foo {
    private String bar = "foobar";

Another code pattern that might prohibit you from setting constructor breakpoints is the use of instance initializer code, such as this:
public class Foo {
    private String bar;

        bar = "foobar";

If you avoid both of these types of code constructs, you should be able to set breakpoints in constructors however you need to. But if for some reason you need the initializing code like either of the above examples, there are a couple of workarounds:
  1. Move most (if not all) of the code that is in your constructor(s) into an init() or initialize() method that is then called by the constructor(s). This is a generally desirable pattern to follow anyway, as it keeps your constructors simple and can help reduce code duplication.

  2. Another option is to use the IBM-specific class DebugSupport to simulate a breakpoint. Placing a call to
    in your code where you would like to break causes VAJ to bring up the debugger at that point. (See How can a breakpoint be set on methods of an inner class? for more information on this method.)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.