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

compiler permits to assign value to blank final variable twice

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      beta3
    • CPU:
      sparc
    • OS:
      solaris_7
    • Verification:
      Verified

      Description



      Name: ngR10089 Date: 04/29/2001



      JLS, 2nd Ed. "16.2.8 switch Statements" says:
          "V is [un]assigned before the first block-statement of any
           block-statement-group other than the first iff V is [un]assigned
           after the switch expression and V is [un]assigned after the last
           block-statement of the preceding block-statement-group."

      Java compiler jdk1.4.0beta-b62 permits to assign value to local blank
      final variable twice. 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-b62)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b62, mixed mode)

      > javac -d . test.java
      > java -Xfuture p.test
      case2 10
      default 14
      >

      -----------------test.java------------------
      package p;

      public class test {
          public static void main(String args[]) {
              System.exit(run(args) + 95/*STATUS_TEMP*/);
          }
       
          public static int run(String args[]) {
              int c = 6;
              final int a1;

              switch (c%(a1=4)) {
                  case 1: c+=1;
                          break;
                  case 2: c+=a1; System.out.println("case2 "+c);
                  default: a1=4;
                           c+=a1; System.out.println("default "+c);
                           break;
              }
              return 2/*STATUS_FAILED*/;
          }
      }
      ----------------------------------------------------

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

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: