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

compiler doesn't give warning for uninitialized variable after try/finally

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      beta3
    • CPU:
      generic, x86, sparc
    • OS:
      generic, solaris_2.6, windows_nt
    • Verification:
      Verified

      Description



      Name: tb29552 Date: 12/15/2000


      /*
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
      Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)

      The 1.3 javac does not output:

      TestCompiler.java:27: Variable a may not have been initialized.
              String a = String.valueOf(a);
                                        ^
      1 error

      for the following code. If you remove the try {...} finally {...},
      then it will find and print the error.

      The 1.2.2_05a javac does output the error message.

      jikes (1.12) also has the same problem as the 1.3 javac.

      */
      public class TestCompiler {
          public static void main(String argv[]) {
              try {
                  String y = "yyy";
              } finally {
              }
              String a = String.valueOf(a);
              System.out.println("a=" + a);
          }
      }

      (Review ID: 113700)
      ======================================================================



      Name: ssT124754 Date: 02/26/2001


      NT:
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      Solaris:
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
      Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)


      The following code will not compile under 1.2.2_05 but will under 1.3.0. With
      1.2.2_05, "Variable tb may not have been initialized." is reported in line 6.
      In 1.3.0 however, it compiles successfully but dies with a VerifyError when you
      try to run it. If the for loop is removed, or even replaced with a while loop,
      1.3.0 will also not compile it.

      import java.util.ArrayList;
      public class TestBug {
        public static void main (String[] args) {
          for (int i = 0; i < 2; i++) {}
          TestBug tb = new TestBug(tb);
        }
        public TestBug (TestBug tb) {}
      }
      (Review ID: 117695)
      ======================================================================
      from 4435094:

      public class Blaa {
        public static void main(String argv[]) {
          { int i = 5; }
          int i = i;
          System.out.println("i: " + i);
        }
      }

      neal.gafter@Eng 2001-04-06
      ======================================================================
      from 4473457:

      /*
      java version "1.3.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

      The following code compiles without error:

      */
      public class BadDay {
              public static void anyMeth() {
                      for(int i=0; i<10; i++); // comment me
                      for(int i=i; i<10; i++);
              }
              public static void main(String [] as) { }
      }
      /*

      The first indication of a problem is when you run the program; the ClassLoader
      gives you this obscure message:

          Exception in thread "main" java.lang.VerifyError: (class: BadDay, method:
          anyMeth signature: ()V) Accessing value from uninitialized register 1


      If you comment out the "comment me" line, the compiler correctly reports:

          BadDay.java:7: variable i might not have been initialized
                          for(int i=i; i<10; i++);
                                    ^
          1 error
      */

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              gafter Neal Gafter
              Reporter:
              tbell Tim Bell
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: