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

Viewed 28299

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.

4 Answers

Adding to @Hari Rao

One small thing I think it is important to mention as it is easy to forget, make sure that the variable itself you're trying to modify is var and not val

Otherwise, you will get the "Set Value" greyed out.

The same in Android Studio. In debug mode go to Variables, select a variable and press Set Value.... If you don't see the variable, expand this list.

enter image description here

Then enter a new value and press Enter.

If you also add into Variables something like someVariable = 1 debugger will change someVariable value every time when it will reach a breakpoint.

Related