Bug 352669 - [README] breakpoint set on "if(true)" line never hit
Summary: [README] breakpoint set on "if(true)" line never hit
Status: RESOLVED DUPLICATE of bug 55459
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Debug-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: readme
Depends on:
Blocks:
 
Reported: 2011-07-20 15:56 EDT by Grant Gayed CLA
Modified: 2012-02-23 13:05 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 ***