Search code examples
javaassertskipbreakpointsstep-into

Java - cannot step into a function when function is called within an assert


So I noticed while debugging a Netbeans Java application when a function call is used in an assert function, you cannot hit a breakpoint within that function or step into that function.

At first I thought it had to do something to do with using an overridden function and my overridden function not being called, but I confirmed that is not what is going on. It still gets called, but cannot be stepped into.

Here is the snippet that I tried:

public class Example
{
    public static boolean blah()
    {
        System.out.println("Executing");    //**Breakpoint here
        return true;
    }

    public static void main(String[] args)
    {
        assert(blah());    //Cannot step into or hit breakpoint on this line.
        blah();            //Can here.
    }
}

Anybody have any ideas why this is not working?


Solution

  • By default, assertions are disabled at runtime.

    Perhaps your debugging JVM does not have assertions enabled.

    To enable assertions, specify the -enableassertions (or -ea) switch for your NetBeans debugging JVM parameters. Even though assertions are compiled into the bytecode, they won't execute without this switch.

    See this link for more