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

REGRESSION: Unreported exception in code with "return" in finally block

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      hopper
    • CPU:
      x86
    • OS:
      windows_nt
    • Verification:
      Verified

      Description



      Name: gm110360 Date: 10/03/2001


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


      /***************************************************
      The following code does not compile with JDK1.3.1_01
      ***********************************************************/

      public class TestException {

        public void f() throws MyException{};
       
        public String execute() {

      try{
      f();
      }
      catch (MyException me) {
      f();
      }
      finally{
      return "next";
      }
        }
      }

      class MyException extends Exception {
      }

      /**************************************************************
      .......
      C:\_bog_java>javac TestException.java
      TestException.java:11: unreported exception MyException; must be caught
      or declared to be thrown
             f();
                   ^
      1 error

      .......

      and it compiles with JDK1.2.1.

      (it compiles with Visual Age for Java 3.02 professional edition and
      does not compiles with Forte for Java CE 3.0
      hence I can not migrate my web application in which this code is used,
      from Visual Age 3.02 to Forte 3.0; this code is bad but my objectif is to make
      run the existing web application with Forte 3.0).

        In my opinion, this situation corresponds to case marked here as "!!!!",in
      paragraphe 14.19.2 of The Java Language Specification (Second Edition)where
      reason S == "return" of finally block .Therefore javac of JDK1.3.1_01 is wrong.


      14.19.2 Execution of try-catch-finally

      A try statement with a finally block is executed by first executing the try
      block. Then there is a choice:

      If execution of the try block completes normally, then the finally block is
      executed, and then there is a choice:

      If the finally block completes normally, then the try statement
      completes normally.
      If the finally block completes abruptly for reason S, then the try
        statement completes abruptly for reason S.

      If execution of the try block completes abruptly because of a throw of a value
      V, then there is a choice:

      If the run-time type of V is assignable to the parameter of any catch
      clause of the try statement, then the first (leftmost) such catch clause is
      selected.
      The value V is assigned to the parameter of the selected catch clause,
      and the Block of that catch clause is executed.
      Then there is a choice:

      If the catch block completes normally, then the finally block
      is executed. Then there is a choice:

      If the finally block completes normally, then the try
        statement completes normally.
      If the finally block completes abruptly for any reason,
      then the try statement completes abruptly for the same reason.

      If the catch block completes abruptly for reason R, then the
      finally block is executed. Then there is a choice:

      If the finally block completes normally, then the try
        statement completes abruptly for reason R.
      !!!! If the finally block completes abruptly for reason S, then the
      try statement completes abruptly for reason S (and reason R is discarded).

      If the run-time type of V is not assignable to the parameter of any
      catch clause of the try statement, then the finally block is executed. Then
      there is a choice:

      If the finally block completes normally, then the try statement
      completes abruptly because of a throw of the value V.
      If the finally block completes abruptly for reason S, then the
      try statement completes abruptly for reason S (and the throw of value V is
      discarded and forgotten).

      If execution of the try block completes abruptly for any other reason R, then
      the finally block is executed. Then there is a choice:

      If the finally block completes normally, then the try statement
      completes abruptly for reason R.
      If the finally block completes abruptly for reason S, then the try
        statement completes abruptly for reason S (and reason R is discarded). The
      example:


      *******************************************/

      Release Regression From : 1.2.1
      The above release value was the last known release where this
      bug was knwon to work. Since then there has been a regression.

      (Review ID: 133050)
      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            gafter Neal Gafter
            Reporter:
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: