Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I modify a variable value while debugging in IntelliJ, so that respective watches are automatically updated?

I have the following piece of code:

Matcher matchDays = m_daysRegex.matcher(e.getKey());
if (matchDays.matches()){
...
}

Where e.getKey() is "Mon-Fri".

Now, I have already executed the first line and stand on the if expression. Using the watch window I evaluate the matchDays.matches() expression and then add some watches on the various methods of matchDays. Then using the same watch window I evaluate the matchDays = m_daysRegex.matcher("Mon,Fri") and matchDays.matches() expressions to see what happens. Unfortunately, the watch window does not refresh itself and it does not have an explicit button to do so: enter image description here

On the image above, notice how matchDays.group(0) displays "Mon,Fri", but matchDays.group(1) displays "Mon-Fri". This is because I manually refreshed the former, but all the rest still show the old values. I have to manually refresh them all, which is annoying.

Am I doing something wrong? Is there the right way to do it, so the watch expressions are refreshed automatically? Or is there a way to refresh the whole watch window?

Thanks.

like image 554
mark Avatar asked Aug 10 '12 10:08

mark


People also ask

Is it possible to change the value of a variable while debugging in IntelliJ?

Select a variable or a property of a complex object in the Debug window, press F2 or right-click and choose Set Value... from the context menu, and then specify a new value and press Enter .

How can the value of a variable be modified while debugging?

You can change a variable in the Evaluate dialog or in the Watch List panel. The Evaluate dialog: To invoke the dialog, press the Call the Evaluate Dialog button on the Debug toolbar, or press the Ctrl+F12 shortcut (this is the default shortcut. You can change it any time.

How do I change the code while debugging in IntelliJ?

Use breakpoint expressions In order to change the flow of your program, you can use non-suspending breakpoints that evaluate an expression when hit. This is useful, for example, when you want to automatically modify your variables during debugging.


1 Answers

To change the value of a variable in runtime in IntelliJ:

  1. Locate the variable in the Variables window.
  2. Right click and select "Set Value…".
  3. Update the value and then hit Enter.
like image 52
Hari Rao Avatar answered Sep 21 '22 08:09

Hari Rao