How to change List value during debugging in IntelliJ

I need to change a variable while debugging an application. So far, these have been just basic variables that could be set directly. Now I need to clear the array so that isEmpty() returns true,

 ArrayList<String> someList = new ArrayList<String>; someList.add("1"); ... if(someList.isEmpty()){ //break point //need to enter here } 

In the intellij debugger, I see:

 someList={ ArrayList@4271 } size=1 

I used the setValue method of the debugger and tried: new ArrayList<String>() or someList = new ArrayList<String>()

that leads to

 someList={ ArrayList@4339 } size=0 

However, if I continue, I get a NullPointerException when isEmpty () is called. So my question is: How can I introduce an empty ArrayList without getting NPE?

NPe text: java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.isEmpty()' on a null object reference

+7
debugging intellij-idea android-studio intellij-14
source share
2 answers

Have you tried to use the expression "Evaluate" during debugging (" Alt + F8 " on Windows)?

In this window you can write:

  someList.clear(); 

or

 someList = new ArrayList<String>(); 

And he has to do the trick.

+8
source share

Stop the breakpoint on if(someList.isEmpty()) , press ALT + F8 (evaluate the expression), enter someList.clear() , press Evaluate and just continue debugging. Now it will definitely go into the if condition.

+3
source share

All Articles