Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edit method return value in a debugger

Tags:

java

debugging

Given the following Java code, how can I use the IntelliJ or Eclipse debugger to return false from the condition() method?

public boolean condition() {
    return (4 == add());
}

public int add() {
    return 2 + 2;
}
like image 643
user675801 Avatar asked Jan 23 '15 01:01

user675801


People also ask

How do I change the value while debugging in Visual Studio?

In most languages supported by Visual Studio, you can edit your code in the middle of a debugging session and continue debugging. To use this feature, click into your code with your cursor while paused in the debugger, make edits, and press F5, F10, or F11 to continue debugging.

How do I go back in debugger?

Open Debug Configuration -> Debugger -> Enable Reverse Debugging at startup . Than you can press shift+F5 or shift+F6 for step back like F5 or F6 for step forward.

Can we go back in debugging?

Sadly it is not possible to go back to a single line, the JVM does not support this.


Video Answer


2 Answers

In Eclipse you can use Force Return.

Just place a breakpoint on return (4 == add()); and type false on the Display view-tab. Then make a selection of your false, right click and hit "Force Return".

like image 144
robert Avatar answered Sep 29 '22 18:09

robert


In IntelliJ (since IDEA 15 EAP) you can use Force return.

Extract from jetbrains' blog

You can force the return from the current method without executing any more instructions from it:

enter image description here

NB :

If the method returns a value, you’ll have to specify it (smart code completion provided).

If the method has try-finally blocks, you’ll be able to choose whether to execute them or not.

like image 41
yunandtidus Avatar answered Sep 29 '22 16:09

yunandtidus