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

Doubly labeled statements should not be continue targets...

    Details

    • Subcomponent:
    • Resolved In Build:
      hopper
    • CPU:
      sparc
    • OS:
      solaris_2.5.1

      Description



      Name: laC46010 Date: 05/19/98



      javac in all versions of JDK from JDK1.0.2 to JDK1.2beta4
      permits to use continue statement with label which doesn't precede a loop.
      It contradicts to JLS (14.14, p.285):

      "A continue statement with label Identifier attempts to transfer
      control to the enclosing labeled statement (14.6) that has the
      same Identifier as its label; that statement, which is called
      the continue target, then immediately ends the current
      iteration and begins a new one."

      JLS 14.6 (p.271) assumes that each label marks only one single statement.
      Then we should consider "A:B:for()..." as consisting of two different statements:

      statement1: A:statement2
      statement2: B:for()

      so for() statement is labeled with only one label: "B" and is not
      labeled with label "A". It means that "continue A" inside this for()
      loop is invalid and must cause compile-time error.

      Note that javac doesn't complain about such error in JCK test case

      lang/STMT/stmt016/stmt01602/stmt01602.java

      and compiles it without any error messages.

      ---------------------------------------------------------------
      // Ident: @(#)stmt01602.java 1.2 97/05/07
      // Copyright 05/07/97 Sun Microsystems, Inc. All Rights Reserved
      package javasoft.sqe.tests.lang.stmt016.stmt01602;


      import java.io.PrintStream;

      public class stmt01602 {

        public static void main(String argv[]) {
           System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
        }
        public static int run(String argv[],PrintStream out) {
           int a1 = 0;
           int a2 = 0;
           int a3 = 0;
           int a4 = 0;
           int i, j = 0;
        a: b:
           for ( i = 0; i < 3; i++ ) {
              a1++;
              if ( i == 0 ) {
                 a2++;
                 continue a;
              }
              if ( i == 1 ) {
                 a3++;
                 continue b;
              }
              a4++;
           }
           if ( a1!=3 || a2!=1 || a3!=1 || a4!=1 ) {
              out.println(a1 + " " + a2 + " " + a3 + " " + a4);
              out.println("failed");
              return 2;
           }
           return 0;
        }
      }
      ---------------------------------------------------------------
        

      Hook 5(hook5): test
      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              gafter Neal Gafter
              Reporter:
              leosunw Leo Leo (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: