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

16.2.12: Clarify DU/DA analysis for loop containing break

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      solaris_8

      Description

      JLS 16.2.11 has a problem with ForUpdate statements. The
      following program gives a compile-time error with javac:

      class C {
        void bar() {
          for (final int i; 0 < (i = 1); i = i + 1)
            break;
        }
      }

      Yet the current wording in the JLS permits it as legal. i is DU after
      the init part, i is both DA and DU after the contained break, and there
      are no continue statements; therefore i is DU before the condition
      expression (16.2.11.d) and may be assigned there. Further, since i is
      both DA and DU after the contained break, and there are no continue
      statements, the increment statement is not violating either rule that a
      variable must be DA before access or DU before assignment. Compare this
      to a program with similar semantics, which does compile:

      class D {
        void bar() {
          final int i;
        label:
          if (0 < (i = 1)) {
            if (true)
              break label;
            i = i + 1;
          }
        }
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                abuckley Alex Buckley
                Reporter:
                gafter Neal Gafter
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: