Let's say I have the following code:
if(shouldDoSomething()) {
// amazing code here
}
And let's also say shouldDoSomething()
is a method I don't have source code for. Is there any way I can force the code into the if
block even if shouldDoSomething()
returns false
? And vice versa?
I know in C++ in Visual Studio I could just change the value in the EAX
register and be on my way, but I didn't know if there was something similar for debugging in Eclipse when code is written in this style?
Refactoring the code to capture the response in a variable is not an option.
Perhaps there is a neater way of doing this, but this should work :
1) Step Into (F5) the method you want to change the return value for. It is fine if you do not have the source code for this method and it steps into a class file.
2) Open the Display View (Window>Show View>Display) and type true
into it
3) Highlight the true
you just typed and right click on it and choose Force Return (or Alt+Shift+F)
4) Continue stepping through your code. If you had your if statement set up as in your question it should now step into the if statement block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With