Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8234922

No compilation error reported not reported for a binding variable when loop broken with label

XMLWordPrintable

    • b26

      The below code uses instanceof in do S while(e) statement. It should throw a compilation error as S contains a reachable break statement whose break target contains S. However, the compilation goes through successfully.

      public class PatternTest {
          static public Object b0 = "bb";

          public static void main(String[] args) {
              String res = "";
              Object bx = b0;
              A:
              do {
                  res += "t";
                  break A;
              } while (!(bx instanceof String v));
              System.out.println("Got: " + v);
          }
      }

      There is a LinkageError thrown at runtime. The error log is attached below.

            jlahoda Jan Lahoda
            vkhatri Vinod Khatri
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: