A conditional breakpoint pauses program execution only when an associated Boolean expression evaluates to true. It lets you investigate a specific runtime state without stepping through every earlier execution. section 3.1 section 3.5
Use one when a line executes repeatedly but only certain values matter—for example, when investigating why sum sometimes becomes zero. In IntelliJ IDEA, add a breakpoint to the line, open its configuration, and enter a condition such as sum == 0. section 3.1
Finding the zero-sum case
In Decoder.decode, the loop extracts digits, sums them, and adds the result to total. If the summing line executes many times, place a conditional breakpoint there with sum == 0. The debugger skips ordinary iterations and pauses only at the suspicious case, where you can inspect the input, digits, call stack, and surrounding state.
Apply conditional breakpoints as an investigative filter:
- State the runtime value or situation you need to prove before choosing the condition. section 3.1
- Use a Boolean expression that can be evaluated at the breakpoint, such as sum == 0. section 3.1
- Inspect the paused execution path and variables instead of repeatedly stepping through irrelevant cases. section 3.1
- For lengthy processes, recognize that waiting for a matching breakpoint may still be impractical; consider changing in-scope values when execution pauses. section 3.3
Listing 3.1 Using conditional breakpoints for investigation
public class Decoder {
public Integer decode(List<String> input) {
try {
int total = 0;
for (String s : input) {
var digits = new StringDigitExtractor(s).extractDigits();
var sum = digits.stream().collect(Collectors.summingInt(i -> i));
total += sum;
}
return total;
} catch (Exception e) {
return -1;
}
}
}
Shows the Java method used to place a conditional breakpoint on a repeatedly executed calculation. section 3.1
