Conditional breakpoints in Java development with Eclipse
Imagine that you have a screen that shows a large list of items with several columns of data for each row. One of the items is showing odd data. You want to step though the code to see what is happening for that row.
If you set a normal breakpoint, you’ll have to break and run repeatedly while manually verifying if the breakpoint is finally being hit for your item of interest.
A better approach is to set a conditional breakpoint. Right click on the breakpoint, select ‘Breakpoint properties…’, check ‘Enable condition’. You can now set a condition for the breakpoint to break. You can use the variables in the context of the breakpoint in this condition. Something like ‘orderNumber.equals(“RA54365″)’.
Now you’ll hit the breakpoint only for the item of interest. Can be quite a bit of a time saver when used in the right situation. Note that the icon for a conditional breakpoint shows up like a regular breakpoint icon with a question mark superimposed on it.
I have also used this at times when I know that something I am doing is resulting in bad data but I’m not sure what. I set a conditional breakpoint and keep trying out things. When I hit the right steps, the breakpoint suspends the thread and alerts me to it. Neat, isn’t it? You can do the same when developing with IDEA or NetBeans too.
Got any cool debugging tips? Drop me a comment!
Tags: Debugging, Eclipse, Java