RFR: JDK-8234922: No compilation error reported not reported for a binding variable when loop broken with label

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Thu Nov 28 18:43:27 UTC 2019


Looks good - I wonder if we really need to store all trees from the 
outer loop down to the break statement.

Shouldn't we just add trees that could potentially be targets of a 
break? (e.g. labels, switch and other loops)

Maurizio

On 28/11/2019 15:11, Jan Lahoda wrote:
> Hi,
>
> Bug: https://bugs.openjdk.java.net/browse/JDK-8234922
>
> The problem described there is basically:
> ---
> public class PatternTest {
>     public static void test(Object o) {
>         A:
>         do {
>             break A;
>         } while (!(o instanceof String v));
>         System.out.println("Got: " + v);
>     }
> }
> ---
>
> This should not compile, as "v" should not be in scope for the 
> System.out.println, but javac fails to detect the break, as the break 
> breaks to a labeled statement, not to the loop. The proposed patch 
> solves not only this, but also break to any statement that is not 
> inside the given loop.
>
> Webrev:
> http://cr.openjdk.java.net/~jlahoda/8234922/webrev.00/
>
> How does this look?
>
> Thanks,
>     Jan


More information about the compiler-dev mailing list