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

JLS3 14.21 When can a statement complete normally? (break&continue versus finally)

XMLWordPrintable

    • rc
    • generic
    • solaris_8
    • Verified

      The treatment of break and continue in the description of reachability
      in the JLS is confusing and contradictory. Specifically, the assignment
      statement below is considered reachable:

              int i;
              a: try {
                  break a;
              } finally {
                  return;
              }
              i = 12; // reachable?

      It is reachable because the break statement is reachable and "there
      is a reachable break statement that exits the labeled statement".

      On the other hand, what does it mean "exits the labeled statement"?
      Certainly the break statement refers to the labelled statement, but
      because of the intervening finally block that cannot complete normally,
      it will never cause control to transfer to the statements following the
      labelled statement.

      A clarification is in order for the meaning of when a break statment
      "exits the labeled statement". A similar clarification is needed for
      the continue statement.

      Two possible but different clarifications might be

      (1) a break statement exits the statment if it is matched with that statement
      by the description in 14.14 AND every intervening finally clause can complete
      normally; or

      (2) a break statement exits the statment if it is matched with that statement
      by the description in 14.14 (whether or not intervening finalizers can
      complete normally)

      Either way we go, we should be explicit in our choice and call the reader's
      attention to the issue so there is no further confusion on the intended
      meaning.

      A large number of javac failures on the jacks test suite boil down to this
      specification question.

            abuckley Alex Buckley
            gafter Neal Gafter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: