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

Definite un-assignment check fails on fall-through from switch case.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 1.1, 1.2.0
    • Fix Version/s: 1.2.0
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      1.2beta
    • CPU:
      sparc
    • OS:
      solaris_2.5, solaris_2.5.1
    • Verification:
      Not verified

      Description

      The following code should fail to compile, but instead it
      will run and report inconsistent values for the supposedly constant "x".
      The definite assignment logic does not recognize that "x" has already
      been assigned by case 1.

      class SwitchDABug {
      static void f(int n) {
      final int x;
      switch (n) {
      case 1:
      x = 1;
      System.out.println(" at first, x == "+x);
      case 2:
      x = 2; // SECOND ASSIGNMENT ON FALL-THROUGH OF CASE 1
      break;
      default:
      x = -1;
      }
      System.out.println("finally, x == "+x);
      }
      public static void main(String av[]) {
      f(1);
      f(2);
      f(3);
      }
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              wmaddoxsunw William Maddox (Inactive)
              Reporter:
              jrose John Rose
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: