Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set a breakpoint on assert in eclipse?

I have a large project consisting of several thousand classes. Today I discovered that for some input, a different result is calculated when running with assertions enabled.

Since the assertion itself doesn't throw an AssertionError (I already have a breakpoint on that one), this means that somewhere hidden in the code is an assertion statement that has an unwanted side effect. The problem is I have no clue which of my >100 assertions is causing the problem.

Since assert is not a method but a keywordin Java, I am at a loss on how to set a breakpoint that will be hit each time assert is called.

Possible workarounds I have found:

  • commenting out assertions one by one and running the program to finally find the culprit.
  • run my test case with a code coverage tool like eclEmma to filter out some of the assertion statements.
  • enabling assertions only for certain packages to narrow down the number of assertions that might be the cause.
  • doing a search and replace (using regular expressions) to replace assert by a utility method where I can place a breakpoint.

Nonetheless, I would like to know if anyone knows of a way to break on assert, even if the condition evaluates to true.

like image 443
Axel Avatar asked Oct 24 '25 17:10

Axel


1 Answers

Goto Run->Add Java Exception Breakpoint Type 'AssertionError' in search box Choose java.lang.AssertionError and OK

Now Eclipse will suspend on assert

like image 178
Fracdroid Avatar answered Oct 26 '25 08:10

Fracdroid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!