简体   繁体   中英

Eclipse Mars (4.5) hot swap code in debugger not working

So I updated to Eclipse Mars (4.5) and for some reason I'm unable to use the hot swap code in the debugger. Normally I could do something like this:

public static void main(String[] args){
    while(true){
        System.out.println("123");
    }
}

Then if I started it in debug mode, changed the text to "321", then save, then it would update without the need for restarting it. It behaves exactly like it was run in "Run" mode instead of "Debug".

What I have tried:

  • Creating a new workspace, creating a fresh project, using the code above, nothing happens
  • Have several JDKs installed, have tried with java 6, 7 & 8, changed the workspace and/or the project settings to use the different JDKs, nothing happens (the fact that I have several versions of java installed shouldn't matter as it was just the moment I updated eclipse it stopped working)
  • Tried uninstalling removing any config files to eclipse (on a mac, so that would be every file/folder with the word "eclipse" in the ~/Library folder, ran a "find" search to detect all the files). Then tried to create a new workspace, now project, the code snipped, ran in debug mode, nothing happens on save.
  • Have also made sure I have "Auto Build" enabled, even tried to "clean" it, and disable auto build, then save the code, then do a manual build while the debugger was running: nothing happens

I'm starting to get desperate as I have a hard time getting work done without having debug mode available so any help/hints in the right direction would be of much appreciation.

HotSwap doesn't work with static methods.
However it works fine with instance methods, so it will work on this code:

public class Main {

    public static void main(String[] args) {
        new Main().f();
    }

    public void f() {
        while(true){
            System.out.println("123");
        }
    }
}

Ok so I finally found the problem. It seems that you can't edit loops while they are running. Say you have a loop like this:

public static void main(String[] args){
    while(true){
        System.out.println("123");
    }
}

Then you can't edit the "123" string. You can how ever edit methods which are called inside the loop like this:

public static void main(String[] args){
    while(true){
        System.out.println(methodA());
    }
}

public static String methodA(){
    return "123";
}

Now you can edit the string "123" and it will update. This also applies for infinite "for" loops, so guess the rule of thumb is that the method body has to be "re-called" before updating, and it isn't enough to wait for the next loop call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM