0

After working with Java in Eclipse for 8 years I switched to IntelliJ Idea. Imagine the "cultural shock" I had hehehe Anyway, there's one thing I really miss and not sure if IntelliJ supports it: easily editing Java code during a breakpoint.

In short, in Eclipse if i edit a line of code below the breakpoint and save the change, it will be automatically applied during program execution. If I edit the line of code above the breakpoint (already executed), Eclipse debugger with move the "running cursor" to the beginning of the function whose code I changed and continue running from there including the changes I just added.

I know that in IntelliJ there's an option to build the module and approve "hot swap" of the code but the project I'm working on is humongous, build takes about 2 minutes and sometimes while investigating I need to make several changes and adjustments while debugging.

Is there an option or plugin for IntelliJ to automatically apply changes below the breakpoint or re-execute the function in case I made changes before the breakpoint?

guest86
  • 2,894
  • 8
  • 49
  • 72
  • By "build" do you mean "compile"? – Bohemian Jun 21 '23 at 21:46
  • Well, in IntellJ Idea there's a menu called "Build" and from there I choose "build project" or "Build module" – guest86 Jun 21 '23 at 21:52
  • Don't do that. IntelliJ automatically compiles your edit. See [JetBrains "Edit running code with Hot Reload" article](https://www.jetbrains.com/help/rider/Hot_Reload.html#Make_changes_when_running), although it does say auto reload only works on Windows. As an aside, I've been coding Java for a very long time and I've never been tempted to do this, nor have I known anyone else to. Another point is the build should be super fast because apps shouldn't be monolithic. It sounds like it's time to split your app up into smaller [microservices](https://en.wikipedia.org/wiki/Microservices). – Bohemian Jun 21 '23 at 22:00
  • Ah, I'm on Linux.... And i'm still just a cog in the company, it's not my project hence I was searching for alternative solution.... – guest86 Jun 21 '23 at 22:37

2 Answers2

0

HotSwap is possible but there are some limitations.

Alternatively, you can use the Dynamic Code Evolution VM(DCEVM) with unlimited support for reloading classes at runtime. There are plugins available that implement it.

JRebel (paid)

Hotswap Agent (free)

0

While your application is being debugged, IntelliJ will ask to hot reload the loaded classes if they are recompiled. This works on GNU+Linux as well; I have never had a problem with this.

If the code was already executed (e.g. your breakpoint is in the middle of a method), you can right-click the top frame in the "Frames" view and select "Drop frame". This will unwind the stack and you can enter the function again. See https://www.jetbrains.com/help/idea/debug-tool-window.html or When using the Java debugger in IntelliJ, what does "Drop Frame" mean?

Note that any side-effects (print statements, modifying external collections, etc.) caused by the first method execution will not be rolled back.

knittl
  • 246,190
  • 53
  • 318
  • 364