Bug 30949 - When compiled from eclipse, unhandled exceptions in try - finally block are not detected.
Summary: When compiled from eclipse, unhandled exceptions in try - finally block are n...
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows 2000
: P3 major (vote)
Target Milestone: 2.1 M5   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 34301 40979 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-02-05 07:51 EST by Jari Holpainen CLA
Modified: 2003-07-31 10:20 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jari Holpainen CLA 2003-02-05 07:51:37 EST
The following code is compiled without a hitch by eclipse 2.0.2 and M4. The 
unhandled Exception is not detected.

package misc;

/**
 * @author ext-toni.nykanen
 *
 * Eclipse 2.0.2. w/ jdk 1.3.1. (the one that comes with bea wls 6.1.)
 * compiles this nicely.
 * 
 * When executed from the command line with jdk 1.3.1. javac, the compiler
 * errors.
 */
public class ExTest {
    private static String foo() {
        try {
	    System.out.println("Toimii");
            throw new Exception();
        } finally {
            return null;
        }
    }
    public static void main(String[] args) {
        foo();
    }
}
Comment 1 Olivier Thomann CLA 2003-02-05 09:11:03 EST
JDK1.4.1 and jikes 1.18 compile this code as well. I would say this is a bug in
JDK1.3.1. The exception is not thrown. It is handled in the finally block and
the result of the method foo is always null.
Comment 2 Philipe Mulet CLA 2003-02-05 10:27:02 EST
Closing, as Olivier said, this code is perfectly legite by the language spec.
Comment 3 Jari Holpainen CLA 2003-02-05 11:13:12 EST
Yes. This is indeed a bug in 1.3.1. Checked from jls later. (Should have done 
it first.)
Comment 4 Olivier Thomann CLA 2003-03-10 08:56:25 EST
*** Bug 34301 has been marked as a duplicate of this bug. ***
Comment 5 Olivier Thomann CLA 2003-07-31 08:51:07 EDT
*** Bug 40979 has been marked as a duplicate of this bug. ***
Comment 6 Lance Zhang CLA 2003-07-31 10:08:43 EDT
I am using Sun JDK 1.4.1 build 1.4.1_02-b06, it gave me the error:


C:\testjava>java -version
java version "1.4.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)

C:\testjava>javac *
ExTest.java:4: unreported exception java.lang.Exception; must be caught or decla
red to be thrown
 try { System.out.println("Toimii"); throw new Exception(); }
                                     ^
1 error

for the same piece of code posted. 




Comment 7 Olivier Thomann CLA 2003-07-31 10:20:02 EDT
I just tried. And I get:
D:\temp>java -version
java version "1.4.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)

D:\temp>cat ExTest.java
public class ExTest {
    private static String foo() {
        try {
            System.out.println("Toimii");
            throw new Exception();
        } finally {
            return null;
        }
    }
    public static void main(String[] args) {
        foo();
    }
}
D:\temp>javac ExTest.java

D:\temp>

So I don't understand what is happening on your machine. What is sure is that 
this was a bug in javac. The exception doesn't need to be handled in your code 
because it is never thrown. The return point of your method is the return 
statement in the finally block. A finally block is always executed. If the 
finally block doesn't return (no return/throw statement inside the finally 
block), then the exception needs to be handled, because it will be rethrown at 
the end of the subroutine.