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

definite unassignment versus assertions

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 5.0
    • 1.4.0
    • specification
    • 1.5
    • generic
    • solaris_8
    • Verified

      The specification for assertions is missing any description of their interaction
      with the try statement. Here is a test case, from the jacks suite, that
      illustrates the underlying question:

      public class T {
          public static void main(final String[] args) {
              final int i;
              try {
                  assert false : i=3;
              } finally {
                  i = 5;
              }
          }
      }

      Is this code legal, or is there an assignment to a possibly assigned
      final variable in the finally clause? I believe there is an error here.
      The suggested JLS wording is to augment the phrase (twice) in 16.2.14
      that reads

      ... V is definitely unassigned after the try block and V is definitely
      unassigned before every return statement that belongs to the try
      block, every throw statement that belongs to the tryblock, every
      break statement that belongs to the try block and whose break target
      contains (or is) the try statement, and every continue statement that
      belongs to the try block and whose continue target contains the try
      statement

      to include

      "and V is definitely unassigned after the last expression in every assert statement that belongs to the try block"

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: