Search code examples
javaintellij-ideareturnjetbrains-ide

IntelliJ doesn't show return value if using Force Step Into?


I'm using the IntelliJ, just want to know when we debug a program using the Force Step Into, the return value doesn't show up in the Variablespanel. I have enabled the Show Method Return Values option. enter image description here

Sample:

    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Map;

    class Main {
        public static void main(String[] args) {
            Map<String, String> map = new HashMap<String, String>();
            map.put("Key", "Value");


            Iterator<String> itr = map.keySet().iterator();    // Debug this line

            while (itr.hasNext()) {
                System.out.println(itr.next());
            }
        }
    }

Debug A(Using Force Step Into + Step Out): I just clicked the force step into onceenter image description here, then click the step out onceenter image description here,they we can see the returned value(main frame) from keySet():

enter image description here

However,

Debug B if we are not using the step out, just keep pressing the force step into enter image description hereand step out enter image description here. Until we finished running the last line of code:

enter image description here

there is no return value(main frame) displayed on the Variable Panel(ks is the return value).

enter image description here

Am I doing something wrong?



Solution

  • I tried to replicate what you are doing in my IntelliJ. What i found is that in case of your Debug B option, If you keep hitting "force step into", then IntelliJ keep digging deeper and deeper and it will take a VERY long time before the program control comes back to the point it returns value in the main method. however, being a very patient person, I went through that and found eventually control does come back to main method and then you will see the return value in variables panel.

    My takeaway from this exercise is that if IntelliJ has information about return value then it displays in debug console. and in order for IntelliJ to get that information, it needs to wait until the code block completes execution. by "force step into", code block takes longer to execute and so we dont see return value immediately. However, by doing "step out", code block completes and we see return value.

    Hope this helps!