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

This code compiles but gives VerifyError when run

XMLWordPrintable

    • b78
    • generic, x86
    • generic, windows_2000
    • Verified

      FULL PRODUCT VERSION :
      1.5.0_04
      1.4.2_05


      ADDITIONAL OS VERSION INFORMATION :
      Windows 2000


      A DESCRIPTION OF THE PROBLEM :
      Compiler does not properly detect all situations in which a variable may be referenced before it is assigned.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the code below.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      CompilerBug.java:5: variable x might be assigned in loop
          while(true) {
          ^
      CompilerBug.java:11: variable x might not have been initialized
          System.out.println(x);
                             ^
      2 errors


      (this is the correct behaviour, produced by JDK 1.3.1_08)

      ACTUAL -
      Exception in thread "main" java.lang.VerifyError: (class: CompilerBug, method: m
      ain signature: ([Ljava/lang/String;)V) Accessing value from uninitialized register 1

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

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      class CompilerBug {

        public static void main(String[] args) {
          final int x;
          while(true) {
            if (true) {
              break;
            }
            x = 1;
          }
          System.out.println(x);
        }
      }

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

            wtaosunw Wei Tao (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: