Fixing Code During a Debugging Session


Using the IDE's Apply Code Changes feature (called Fix in NetBeans IDE 4.0), it is possible to fine-tune code in the middle of a debugging session and continue debugging without starting a new debugging session. This can save you a lot of time that would otherwise be spent waiting for sources to be rebuilt and restarting your debugging session.

The Apply Code Changes feature is useful for situations such as when you need to:

  • Fine-tune the appearance of a visual component that you have created.

  • Change the logic within a method.

Applying code changes does not work if you do any of the following during the debugging session:

  • Add or remove methods or fields.

  • Change the access modifiers of a class, field, or method.

  • Refactor the class hierarchy.

  • Change code that has not yet been loaded into the virtual machine.

To use the Apply Code Changes command while debugging:

  1. When execution is suspended during a debugging session, make whatever code changes are necessary in the Source Editor.

  2. Choose Run | Apply Code Changes to recompile the file and make the recompiled class available to the debugger.

  3. Load the fixed code into the debugger.

    If you are changing the current method, this is done automatically. The method is automatically "popped" from the call stack, meaning that the program counter returns to the line where the method is called. Then you can run the changed code by stepping back into the method (F7) or stepping over the method (F8).

    For a UI element, such as a JDialog component, you can close the component (or the component's container) and then reopen it to load the fixed code in the debugger.

  4. Repeat steps 1 through 3 as necessary.



NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 279

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net