19

I have tried this back and forth for a longer time, but somehow it does not work.

enter image description here

I have also tried with and without semicolon. I have also tried to run this line right before the breakpoint to make sure the condition really works,

logger.error("I am Here! " + "#PDU Elements: " + pdu.getVariables().size());

and it returns 13 as expected.

Does anyone know how to get this to work?

EDIT

On request I will add the lines of code run, at the breakpoint,

logger.error("I am Here! " + "#PDU Elements: " + pdu.getVariables().size());
Trap trap = Trap.createTrapFrom(variableMap, instanceIdentificationNumber); // Breakpoint in margin on this line.

EDIT 2

The problem seems to be related to that IDEA randomly misses some breakpoints. I have also tried some unconditional breakpoints (should always stop) and these only stops at specific times.

patrik
  • 4,506
  • 6
  • 24
  • 48
  • can u put this condition in your code and see if its stopping there ? – Amit May 22 '17 at 13:45
  • @AmitK The code snippet written in the logger is placed just before the breakpoint. It prints it correct, so I am sure the condition is fullfilled. – patrik May 22 '17 at 13:46
  • 1
    can you also provide your line of code, where you putting this condition breakpoint ? – Amit May 22 '17 at 13:47
  • For testing purpose, could you store the value in a variable e.g `int k = pdu.getVariables().size();` and simply put `k==13` as a condition and check if this works ? – Arnaud May 22 '17 at 13:50
  • @patrik , line on which you are putting the condition breakpoint is not having matching condition `pdu.getVariables().size()` , thats the reason its not stopping there. – Amit May 22 '17 at 13:52
  • you can try `if(pdu.getVariables().size()) { //do something }` and put breakpoint on this line. it will stop there – Amit May 22 '17 at 13:53
  • @AmitK So you mean that the expression to evaluate needs be the same as evaluated on the line? – patrik May 22 '17 at 13:54
  • @patrik , Check that you have debug enabled , does it stops in this line without conditions ? – Mike Adamenko May 22 '17 at 13:55
  • @patrik , no but at least expression should be there which can determine whether given condition is true or false. please see previous comment to understand it ore. – Amit May 22 '17 at 13:55
  • @AmitK I tried to set the breakpoint on this line as well, and it does not work `if (pdu.getVariables().size()==13) {;}` – patrik May 22 '17 at 13:59
  • @MikeAdamenko It worked with the expression `int k = pdu.getVariables().size(); k == 13;`. Thanks! If you write it as an answer I will accept it. – patrik May 22 '17 at 14:03
  • @patrik it means that your debugger wasn't enabled ? – Amit May 22 '17 at 14:05
  • @patrik you're welcome ) added as answer. – Mike Adamenko May 22 '17 at 14:05
  • @patrik : maybe you were talking to me, so I added an answer . Tell me if I'm wrong . – Arnaud May 22 '17 at 14:10

5 Answers5

18

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

enter image description here

holi-java
  • 29,655
  • 7
  • 72
  • 83
  • I looked at this help section as well. Actually it did not state any working examples which is a bit sad since the condition have to look something like this `int k = pdu.getVariables().size(); k == 13;`, which I see as extremely weird and possible a bug. – patrik May 22 '17 at 14:06
  • @patrik multi-statements should add a `return` keyword. the code support java syntax. e.g: `int k = pdu.getVariables().size(); return k == 13;` – holi-java May 22 '17 at 14:09
  • @patrik , i added similar condition and it stops for me – Amit May 22 '17 at 14:11
  • @patrik as I have said it is java code, maybe your condition throws a `NullPointerException` to interrupt. and I have test that condition not support lambda expression, so you need transform it with ternary operator statements. please try this `pdu.getVariables()==null ? false : pdu.getVariables().size()==13`; – holi-java May 22 '17 at 14:32
  • @holi-java Yes I have looked a bit and it seems as if there can be a bug. I have tried some other stuff as well (why I have not been able to answer all comments.). I will consider removing this since the question can be seen as misleading. – patrik May 22 '17 at 14:38
  • @patrik Essentially, the help documentation is already mentioned that is a java boolean expression and supports statements of multi-lines, except lambda expression is not has been introduced. – holi-java May 22 '17 at 14:49
2

Just click Right Mouse Button on your breakpoint

enter image description here

CTRL+Shift+F8 or CMD+Shift+F8 to view all active breakpoints enter image description here

D. Naumov
  • 140
  • 2
  • 7
0

You need to put conditional breakpoint at a line which can evaluate your given condition on that line , if that line can't evaluate that condition then your debugger will never stop at that line.

For example :-

public class DebbuerEx {

    public static void main(String[] args) {
        HashMap<String,String > map = new HashMap<>();
        map.put("Amit","k");
        map.put("Jaipur","Rajasthan");
        if(true) {
            //map.remove("Amit");
        }
        for(Map.Entry<String,String> entry : map.entrySet() ) {
            System.out.println(entry.getKey() + " " + entry.getValue());
        }
    }
}

In Above code if i put a conditional breakpoint like below screen-shot it will never stop.

enter image description here

But if change the if condition to if(map.containsKey("Amit")) then same conditional breakpoint will stop there.

Amit
  • 30,756
  • 6
  • 57
  • 88
0

You should check that you have debug enabled and it stops in this line without conditions.

Check the mute breakpoints button in the Intellij IDEA.

UPDATED

Check the installed plugins. Try to disable some of them.

Mike Adamenko
  • 2,944
  • 1
  • 15
  • 28
  • Actually I mean that what was working was storing the result in a variable `k` in the breakpoint. So the breakpoint condition is `int k = pdu.getVariables().size(); k == 13;`. This works, but direct evaluation does not. It looks very much like a bug, but it is hard to say if it was intended. – patrik May 22 '17 at 14:09
  • Very strange, what version of IDEA are you using ? – Mike Adamenko May 22 '17 at 14:14
  • The bug can be result of some your plugins. Updated the answer. – Mike Adamenko May 22 '17 at 14:20
  • I am afraid I am unable to check the plugins. For the record, the semi-colon needs to be removed as well `int k = pdu.getVariables().size(); k == 13`. I have no idea why this happens. Thanks anyway – patrik May 22 '17 at 14:25
-1

There may be better ways to do what you want, but at least you could store the value in a variable in your code, e.g :

int k = pdu.getVariables().size();

then use its value :

k==13 

as a condition for your breakpoint .

Arnaud
  • 17,229
  • 3
  • 31
  • 44