Community
Participate
Working Groups
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
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
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.
*** This bug has been marked as a duplicate of bug 55459 ***