Bug 34301 - Java compiler doesn't dected always unreported exception
Summary: Java compiler doesn't dected always unreported exception
Status: RESOLVED DUPLICATE of bug 30949
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows 2000
: P3 critical (vote)
Target Milestone: 2.1 RC3   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-03-10 08:43 EST by Gaetano Di Gregorio CLA
Modified: 2003-03-10 10:04 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gaetano Di Gregorio CLA 2003-03-10 08:43:32 EST
Eclipse 2.1 M5 Build 200302061700

This code compiles without any problems:

import java.io.*;
import java.util.ArrayList;

public class TestException {

    public ArrayList funcTest() {
        boolean returnNull = true;
        try {    
            File file = new File("whatever string");
            returnNull = file.createNewFile();
        }
        finally {
            if (returnNull)
                return null;
            else
                return new ArrayList();
        }
    }
}

I was expecting the compiler had complained because this method doesn't
catch or throws IOException.

Compiling with javac in a command prompt returns this error:

C:\Temp>javac TestException.java
TestException.java:10: unreported exception java.io.IOException; must be
caught
or declared to be thrown
            returnNull = file.createNewFile();
                             ^
1 error
Comment 1 Olivier Thomann CLA 2003-03-10 08:56:24 EST
Duplicate of bug 30949. This is not a bug. javac 1.3.1 has a bug. The finally
block returns. Therefore there is no uncaught exceptions.

*** This bug has been marked as a duplicate of 30949 ***
Comment 2 Gaetano Di Gregorio CLA 2003-03-10 09:21:43 EST
According the language specification at 
http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#23665
3 

- 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 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.

It should throw an IOException if the createNewFile() throw such an
exception, no ?

Unless I don't understand this spec :(
Comment 3 Jerome Lanneluc CLA 2003-03-10 09:41:48 EST
According 
to 'http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#5
894', the return statement in the finally block makes the finally block 
complete abruptly.
Comment 4 Gaetano Di Gregorio CLA 2003-03-10 10:04:47 EST
I see now that you're right. Thanks for the explanation. I Was confused because
of javac 1.3.1 bug.

This bug can be closed.