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

labels with the same name are allowed for nested blocks

XMLWordPrintable

    • 1.2beta3
    • generic, x86, sparc
    • generic, solaris_2.4, solaris_2.5, windows_95
    • Verified

      Java language specification says (13.6, p.216):

      "A statement labeled by an identifier must not appear anywhere within
      another statement labelled by the same identifier, or a compile-time
      error will occur. Two statements can be labeled by the same identifier
      if neither statement contains the other."

      Java compiler doesn't diagnose the case when two labels
      with the same name are used in nested blocks.
      See an example below:

      > cat stmt127.java
      class stmt127 {

        public static void main(String argv[])
        {

           int j = 0;
       L0: {
          L0: if ( j == 0 )
                 break L0;
              System.out.println(" j = " + j);
           }
        }
      }
      > /usr/local/java/1.0/bin/javac stmt127.java
      > /usr/local/java/1.0/bin/java stmt127
       j = 0

            tturnidgsunw Todd Turnidge (Inactive)
            leosunw Leo Leo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: