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

compiler permits to assign value to final variable twice in try

XMLWordPrintable

    • beta3
    • sparc
    • solaris_7
    • Verified



      Name: ngR10089 Date: 05/15/2001



      JLS, 2nd Ed. "16.2.14 try Statements", p.425 says:
          "V is definitely unassigned before the finally block iff 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 try block, 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 and V is definitely
           unassigned after every catch block of the try statement."

      Java compiler jdk1.4.0beta-b64 permits to assign value to local blank final
      variable in finally block although the variable was assigned in catch block.
      It compiles the test below without error message.

      > java -version
      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b64)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b64, mixed mode)

      > javac -d . dasg15901m7.java
      > java -Xfuture p.dasg15901m7
      java.lang.Exception
      6
      7
      >

      -----------------dasg15901m7.java------------------
      package p;
        
      public class dasg15901m7 {
          public static void main(String argv[]) {
              System.exit(run(argv) + 95/*STATUS_TEMP*/);
          }
              
          public static int run(String argv[]) {
              int c = 0;
              int a = 2;
              final int a1;

              try {
                  if (a == 2) {
                      throw new Exception();
                  }
              } catch (Throwable e) {
                  System.out.println(e);
                  a1 = 6;
                  System.out.println(a1);
              } finally {
                  c = (a1=7) + 1;
                  System.out.println(a1);
              };
              return 2/*STATUS_FAILED*/;
          }
      }
      ----------------------------------------------------

      ======================================================================

            gafter Neal Gafter (Inactive)
            nvgsunw Nvg Nvg (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: