How to use conditions in breakpoints in idea?
press CTRL+SHIFT+F8
twice quickly at your breakpoints will open a dialog not a popup dialog to configure a condition. then press F1
to opening the helping dialog.
as intellij help documentation says a breakpoint condition is:
Select this check box and specify a condition for hitting a breakpoint in the text field. A condition is a Java Boolean expression (including a method returning true or false), for example, str1.equals(str2). This expression should be valid at the line where the breakpoint is set, and is evaluated every time the breakpoint is reached. If the evaluation result is true, user-selected actions are performed. If the result is false, the breakpoint does not produce any effect. If the Debugger cannot evaluate the expression, it displays the Condition evaluation error message. You can select whether you would like to stop at this breakpoint or ignore it. Conditions for field/method/exception breakpoints are calculated in the context for the given field/method/exception. To the right of the Condition field, there is the button (Shift+Enter) that opens the multiline editor.
Note
breakpoint condition is consist with java code, so any error occurs in condition will stop at the breakpoint. and it does not supports any lambda expressions. when you calculate the condition with multi-statements you need using return
statement to return the result.
AND the condition often throws NullPointerException
to stop the breakpoint. you need check null
in breakpoint condition:
//change the condition
pdu.getVariables().size() == 13
^-----throws a NullPointerException if variables is null
//to the condition using ternary operator for checking null
pdu.getVariables()==null ? false : pdu.getVariables().size()==13
Examples
for example:
private String[] run(Class<?> mainClass
, Optional<String> launcherClass, String[] args) {
...
^-----I mark a breakpoint here
}
my condition is and remeber to check the condition checkbox:
launcherClass != null
My Breakpoint Condition Screenshot
Just click Right Mouse Button
on your breakpoint
CTRL+Shift+F8
or CMD+Shift+F8
to view all active breakpoints