Change Java code at runtime with IntelliJ debugging tools
Once you place a breakpoint, you can add Java code to execute (just before the current instruction) in the Evaluate and log
field. In this case I’m setting the “mentionedUserIds” to a hardcoded value.
You can of course change this at the next execution.
If you don’t see the field, click More
to expand the window.
It’s a feature I assume most developers know, but I’ve seen some devs writing some code, then restarting the app, then removing the code (risking the accidental commit). For simple variable changes, this approach is simpler, so I thought I’d make an article.
More on IntelliJ breakpoints here
You can also alter the execution flow by returning from a method or throwing an exception, see here
Thanks for reading !
What to do next:
- Clap if useful
- Buy me a coffee
- Follow me for more
- Read my other articles below or from my profile
- Keep in touch on LinkedIn