VerifyError with switch statement

XMLWordPrintable

    • Type: Bug
    • Resolution: Duplicate
    • Priority: P3
    • None
    • Affects Version/s: 1.4.0
    • Component/s: tools
    • x86
    • linux



      Name: nt126004 Date: 09/20/2002


      FULL PRODUCT VERSION :
      java version "1.4.0-beta3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
      Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)


      FULL OPERATING SYSTEM VERSION :

      glibc-2.2.4-19.3
      Linux quaffle 2.4.9-31smp #1 SMP Tue Feb 26 06:55:00 EST
      2002 i686 unknown
      /etc/redhat-release

      ADDITIONAL OPERATING SYSTEMS :

      The bug is OS independent, so all systems are affected

      A DESCRIPTION OF THE PROBLEM :
      The Javac compiler fails to correctly compile switch
        statements. As a result, the class files either have
      VerifyErrors, of variables are lost because of cross-scoping
      issues.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. `javac Foo.java`
      2. `java Foo`
      3. `java Bar a b`

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Step 1. Compilation should and does succeed - both classes
      are legal: even though the declaration of i occurs in dead
      code (as evidenced by the fact that the initializer
      expression is not even emitted in bytecode), i is in scope
      for case 2.

      Step 2. Actual results should be similar to
      "[Ljava.lang.String;@3f5d07", not "Exception in thread
      "main" java.lang.VerifyError: (class: Foo, method: main
      signature: ([Ljava/lang/String;)V) Accessing value from
      uninitialized register 0".

      Step 3. Actual results should be similar to
      "[Ljava.lang.String;@3f5d07", not "2".

      I think the bug is occuring because i is declared in a dead
      code region. The compiler is not properly assigning it a
      unique local variable number, but is using slot 0 instead.


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.VerifyError: (class: Foo, method: main
      signature: ([Ljava/lang/String;)V) Accessing value from uninitialized register 0

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      class Foo {
         public static void main(String[] args) {
           switch (args.length) {
           case 1:
             if (true)
               return;
             int i = 1;
           case 2:
             i = 2;
           }
           System.out.println(args);
         }
      }

      class Bar {
        public static void main(String[] args) {
          switch (args.length) {
          case 1:
            if (true)
              return;
            Object i = "1";
          case 2:
            i = "2";
          }
          System.out.println(args);
        }
      }

      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      Do not declare variables in dead code regions of switch
      blocks.
      (Review ID: 153809)
      ======================================================================

            Assignee:
            Neal Gafter (Inactive)
            Reporter:
            Nathanael Thompson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: