Community
Participate
Working Groups
Compile the following code: package com.example; public class Loop { public static void main(String[] args) { System.out.println("starting"); Loop l = new Loop(); l.testLoop(); System.out.println("finished"); } public void testLoop() { int loops = 0; do { System.out.println("Loop " + loops); if (loops > 2) { return; } if (loops < 4) { ++loops; continue; } } while (false); } } The code does not terminate as expected. When looking at the bytecode for method testLoop(), the goto instruction at offset 38, just does a goto 38. In a more complex example inside our code, the goto was a completely invalid offset, causing a verifier error.
Created attachment 38020 [details] Decompiled class file
The bug comes from the while(false) and the usage of a continue statement. In this case we never placed the corresponding label. Philippe, we could either place the label even if the condition is false or nullify the continue label in this case.
Created attachment 38021 [details] Proposed fix This patch places the continueLabel even if the condition is the constant false. This is in case the continueLabel has not been nullify in the data flow analysis. The test case runs ok with this fix. I'll run all tests to validate it.
Philippe, Candidate for RC1.
Created attachment 38022 [details] Regression test Add test in org.eclipse.jdt.core.tests.compiler.regression.FlowAnalysisTest
Definitely RC1 candidate. Will look into it.
Came up with same fix. Added FlowAnalysisTest#test024. Fixed
Test got renumbered to FlowAnalysisTest#test025 indeed. Verified for 3.2 RC1 using Build id: I20060413-0010.