How to use conditions at breakpoints in an idea?

I have tried this over and over for a long time, but somehow it doesn't work.

enter image description here

I also tried with and without a comma. I also tried running this line right in front of 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 make this work?

EDIT

Upon request, I will add the code run lines 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 due to the IDEA accidentally missing some breakpoints. I also tried some unconditional breakpoints (should always stop), and they stop only at certain times.

+4
source share
4

CTRL+SHIFT+F8 , , , . F1, .

intellij , :

. - Java ( , true false), str1.equals(str2). , ​​ , , . , . , . , Condition condition. , . // //. "" (Shift + Enter), .

java-, . -. , return, .

NullPointerException, . null :

//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

:

private String[] run(Class<?> mainClass
     , Optional<String> launcherClass, String[] args) {
    ...
    ^-----I mark a breakpoint here
}

check:

launcherClass != null

enter image description here

+1

, , , .

: -

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());
        }
    }
}

, , , .

enter image description here

if if(map.containsKey("Amit")), ​​ .

0

, debug, .

Intellij IDEA.

. .

0

There may be more efficient ways to do what you want, but at least you can store the value in a variable in your code, for example:

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

then use its value:

k==13 

as a condition for your breakpoint.

0
source

Source: https://habr.com/ru/post/1677695/


All Articles