apache / netbeans

Apache NetBeans
https://netbeans.apache.org/
Apache License 2.0
2.62k stars 841 forks source link

Debug info not updated when code dynamically re-loaded #4754

Open blakemcbride opened 1 year ago

blakemcbride commented 1 year ago

Apache NetBeans version

Apache NetBeans 15

What happened

Rather than compiling code and then running it, my system compiles, dynamically loads, and then runs code all at runtime. The benefit of this is that code can be changed at runtime on a live system without having to compile or re-boot a production server. This is something I have been using for years in production environments. It works well. The actual source code for this is at https://github.com/blakemcbride/Kiss

Previously, I used IntelliJ. Debugging this code in a live environment and changing it dynamically worked as expected. However, NetBeans doesn't seem to update its debug info when I dynamically change code. The first time I execute the code, NetBeans debugs fine. However, after I change the code, NetBeans seems to have its line numbers off. So, the new code is executing, but NetBeans is using debug info from the original load.

Again, this is production code that has been working perfectly for years. With IntelliJ, I have been able to debug updated code without a problem. And there has never been a problem in production. When I update a file, the new code gets executed just fine.

I created two videos that demonstrate the problem. The first video shows code that is dynamically loaded. It debugs just fine. The second video shows the same debug session, but after the code has been changed and re-loaded. You can see that NetBeans is using the wrong line number information.

Although the video is showing Groovy code, the same problem exists with Java code. The example code I make available shows both.

Here are links to the two videos.

https://private.stack360.io/files/debug-1.mkv https://private.stack360.io/files/debug-2.mkv

(Please let me know if you need a different movie file type.)

How to reproduce

No response

Did this work correctly in an earlier version?

No / Don't know

Operating System

Fedora Linux

JDK

17

Apache NetBeans packaging

Apache NetBeans binary zip

Anything else

Although my example and use is with Groovy code. I am very inclined to believe that this same issue would occur with Java code as well because, in essence, it is just a dynamic re-load of a class into the JVM.

Are you willing to submit a pull request?

No

Code of Conduct

Yes

lkishalmi commented 1 year ago

I can assure you that the dynamic class reloading for debugging is working in Java projects. Just tested, it works with Groovy as well (though I could imagine, that there are limitations) I have to mention that I've tested this with Gradle projects which probably is the best project type for Groovy support in NetBeans.

blakemcbride commented 1 year ago

You can assure me? Have you seen my videos? Clearly, it's not working.

I remind you that I have debugged this code with IntelliJ for many years without a problem. So, the difference between these two scenarios is NetBeans.

Also, this is not some wacky test project. This is a large system that has been in production for more than ten years.

blakemcbride commented 1 year ago

If you like, I can create a smallish open-source program to demonstrate the problem.

blakemcbride commented 1 year ago

Also, you can't test this with a typical Gradle project because Gradle compiles the code before it gets executed. I'm not doing that, as I've explained.

BradWalker commented 1 year ago

If you like, I can create a smallish open-source program to demonstrate the problem.

That would be extremely HELPFUL! My professional experience has taught me a small reproducible test case goes a very long ways to helping with fixing/diagnosing a problem.

Then maybe others, like me, can get more involved.

blakemcbride commented 1 year ago

The test program is at https://private.stack360.io/files/Test.zip

In it, there is a file named README.txt that has the instructions.

Thank you!

blakemcbride commented 1 year ago

I just updated Test.zip with a few corrections to the README.txt file.

blakemcbride commented 1 year ago

I updated it again to include the NetBeans project files.

lkishalmi commented 1 year ago

I see what you mean! I think so far the debug info loading happened in one direction IDE -> APP, or in the first use IDE <- APP, but after the first IDA <- APP sync the IDE never syncs the debug info back from the APP.

blakemcbride commented 1 year ago

Exactly. Thank you!

blakemcbride commented 1 year ago

That system also dynamically loads Java. I tested it. The problem exists in Java too. So, this is not a Groovy problem.

neilcsmith-net commented 1 year ago

I develop a dynamic reloading system myself, although I've never used the debugger with it - partly because the dynamic source code doesn't exist in files on disk either.

A question would be how you're doing reload? I haven't looked at your system. But in terms of Java at least do you use HotSwap or dynamic classloaders? Because there could be a 1-to-1 vs 1-to-many mapping between source and class to consider too.

blakemcbride commented 1 year ago

When I load a new version, I remove all references to the old class. So there is only one loaded at a time.

If memory serves, Groovy has the ability to dynamically compile and load files built-in. For Java, I use https://github.com/dvare/dynamic-loader

blakemcbride commented 1 year ago

I am interested in funding a project to correct this problem. If interested, please contact me. Blake McBride blake1024@gmail.com

neilcsmith-net commented 1 year ago

I'm aware of dynamic-loader - it's similar, although simpler, to how PraxisCORE works. Feel free to contact me (company info on my GitHub profile). It might be something I can take a look at.

blakemcbride commented 1 year ago

Neil was unable to help me, so this is still an open project.

blakemcbride commented 1 year ago

Incidentally, I noticed that not only does IntelliJ handle this situation correctly, but so does eclipse. So, the only major IDE that doesn't is NetBeans.