Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 352669

Summary: [README] breakpoint set on "if(true)" line never hit
Product: [Eclipse Project] JDT Reporter: Grant Gayed <grant_gayed>
Component: DebugAssignee: JDT-Debug-Inbox <jdt-debug-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: markus.kell.r, Michael_Rennie, Olivier_Thomann
Version: 3.7Keywords: readme
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Grant Gayed CLA 2011-07-20 15:56:05 EDT
I20110719-0800

- create a class with main method:
    public static void main(String[] args) {
        if (true) {
            int j = 0;
        }
    }
- set a breakpoint on the "if (true) {" line
- debug it, the breakpoint is never hit
- set another breakpoint on the line below, debug it, note that this new breakpoint is hit, but the original one still is not
Comment 1 Michael Rennie CLA 2011-07-26 12:33:06 EDT
This is working fine, albeit a bit confusing.

The reason the breakpoint is not hit is because the if statement is being in-lined by the compiler (thanks Olivier for confirming this) - for both javac and the Eclipse compiler.

For example the following snippet:

if (true) {
  System.out.println("Hello World");
}

looks like the following in the class file:

0  getstatic java.lang.System.out : java.io.PrintStream [19]
3  ldc <String "Hello World"> [25]
5  invokevirtual java.io.PrintStream.println(java.lang.String) : void [27]
8  return
Comment 2 Grant Gayed CLA 2011-07-26 12:54:35 EDT
I thought this might be the case.  However it's misleading to allow a user to set a breakpoint there, show it visually in the gutter, and then just ignore it when debugging.  I found this because it's something I actually tried to do last week.  Since it allowed me to set the bp there I guessed that the compiler optimization of the "if (true)" might somehow not apply when run in debug mode, and that the bp would be hit.
Comment 3 Markus Keller CLA 2012-02-23 13:05:01 EST

*** This bug has been marked as a duplicate of bug 55459 ***