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

variable that isn't definitely assigned after try statement are permitted

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5.1

      Description



      Name: ngC57085 Date: 06/25/99



      Java compiler jdk1.3H successfully compiles next jck tests,
      checking definitely assigned variable after a try statement:

      lang/DASG/dasg107/dasg10702m021/dasg10702m021.html
      lang/DASG/dasg107/dasg10702m111/dasg10702m111.html
      lang/DASG/dasg107/dasg10702m311/dasg10702m311.html

      while error messages should be reported. The execution of compiled
      class causes the java.lang.VerifyError.


      >java -version
      java version "1.3"
      Classic VM (build JDK-1.3-H, green threads, sunwjit)

      > javac -d . dasg10702m021.java
      > java javasoft.sqe.tests.lang.dasg107.dasg10702m021.dasg10702m021
      Exception in thread "main" java.lang.VerifyError: (class: javasoft/sqe/tests/lang/dasg107/dasg10702m021/dasg10702m021, method: run signature: ([Ljava/lang/String;Ljava/io/PrintStream;)I) Accessing value from uninitialized register 5

      The oldjavac reports the error message.

      > oldjavac -d . dasg10702m021.java
      dasg10702m021.java:26: Variable i may not have been initialized.
      out.println(i);
      ^
      1 error


      -----------------dasg10702m021.java------------------
      package javasoft.sqe.tests.lang.dasg107.dasg10702m021;

      import java.io.PrintStream;

      class E1 extends Exception {}
      class E2 extends Exception {}

      public class dasg10702m021 {
      public static void main(String argv[]) {
      System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
      }

      public static int run(String argv[], PrintStream out) {
      boolean t = true;
      E1 se1 = new E1();
      E2 se2 = new E2();
      {
      int i;
      try {
      if (t) {
      throw se1;
      }
      } catch (E1 e) { i = 0; }


      out.println(i);
      }
      out.println("Error : there should be compile-time errors");
      return 2/*STATUS_FAILED*/;
      }
      }
      -----------------------------------------------------
      -----------------dasg10702m111.java------------------
      package javasoft.sqe.tests.lang.dasg107.dasg10702m111;

      import java.io.PrintStream;

      class E1 extends Exception {}
      class E2 extends Exception {}

      public class dasg10702m111 {
      public static void main(String argv[]) {
      System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
      }

      public static int run(String argv[], PrintStream out) {
      boolean t = true;
      E1 se1 = new E1();
      E2 se2 = new E2();
      {
      int i;
      try {
      if (t) {
      i = 0;
      throw se1;
      } else {
      throw se2;
      }
      } catch (E1 e) {} catch (E2 e) { i = 0; }


      out.println(i);
      }
      out.println("Error : there should be compile-time errors");
      return 2/*STATUS_FAILED*/;
      }
      }
      -----------------------------------------------------
      -----------------dasg10702m311.java------------------
      package javasoft.sqe.tests.lang.dasg107.dasg10702m311;

      import java.io.PrintStream;

      class E1 extends Exception {}
      class E2 extends Exception {}

      public class dasg10702m311 {
      public static void main(String argv[]) {
      System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
      }

      public static int run(String argv[], PrintStream out) {
      boolean t = true;
      E1 se1 = new E1();
      E2 se2 = new E2();
      {
      int i;
      try {
      i = 0;
      if (t) throw se1; else throw se2;
      } catch (E1 e) {} catch (E2 e) { i = 0; }


      out.println(i);
      }
      out.println("Error : there should be compile-time errors");
      return 2/*STATUS_FAILED*/;
      }
      }
      ----------------------------------------------------


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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              iris Iris Clark
              Reporter:
              duke J. Duke (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: