Possible compiler bug: continue is skipped after or-condition
Roland Illig
roland.illig at gmx.de
Mon Feb 17 17:35:51 UTC 2020
On 17.02.2020 15:45, B. Blaser wrote:
> Roland,
>
> I believe the current behavior to skip line 7, as you described below,
> looks correct.
Why do you think so? I disagree with you. I think a breakpoint in line 7
should be reached 2 times in this example. Once for the string "1a" and
once for "1b". It's surprising that the breakpoint is skipped for all
but the last term of the || expression.
> Maybe someone else could comment on this but I'm not sure the gain
> would worth the pain as you could certainly put a breakpoint on line
> 5.
Not with the same effect. The breakpoint in line 5 is visited 7 times in
this program, while the breakpoint in line 7 is only visited in the
cases "1a" and "1b". Therefore, setting a breakpoint in line 5 is
impractical.
Everyone who steps through source code using a debugger relies that the
line number information is stored correctly. Isn't the debugger support
the main reason for having the line numbers in the bytecode at all?
How would you explain to an average developer that breakpoints are not
reliable? Up to now, they have been very reliable to me, and after more
than 20 years of using Java, this is really the first time that the
breakpoints surprise me.
Roland
>> On 08.02.2020 20:05, Roland Illig wrote:
>>> /* - */ public class Demo {
>>> /* - */ static String[] strings = {"1a", "1b", "2", "3"};
>>> /* - */
>>> /* - */ public static void main(String[] args) {
>>> /* 5 */ for (String s : strings) {
>>> /* 6 */ if (s.equals("1a") || s.equals("1b")) {
>>> /* 7 */ continue;
>>> /* - */ }
>>> /* 9 */ if (s.equals("2")) {
>>> /* - */ continue;
>>> /* - */ }
>>> /* - */ System.out.println(s);
>>> /* - */ }
>>> /* - */ }
>>> /* - */ }
More information about the compiler-dev
mailing list