Bug 46421 - Compiler doesn't require 'throws' declaration when class throws IOException
Summary: Compiler doesn't require 'throws' declaration when class throws IOException
Status: RESOLVED DUPLICATE of bug 22445
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.0 M5   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-11-11 13:01 EST by Philip Gust CLA
Modified: 2003-11-11 15:40 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 Philip Gust CLA 2003-11-11 13:01:20 EST
On Version: 3.0.0 Build id: 200310101454 the incremental compiler does not 
require me to add a 'throws' declaration when my method catches and rethrows a 
java.io.IOException.  With the appropriate options enabled, the IDE also 
reports a warning when I add the 'throws' declaration that the declared 
IOException is not actually thrown by the method.  Sun's javac flags the 
missing 'throws' declaration as an error. I've marked this 'major' because it 
compromises the integrity of compile-time verification.

Here is the method:

        private byte[] getSomeBytes(InputStream in, long length) 
            throws IOException
        {
            DataInputStream din = new DataInputStream(in);
            byte[] bytes = new byte[(int)length];
            try {
                din.readFully(bytes);
            } catch (IOException ex) {
                MessageHandler.error(ex);  // log exception
                throw ex;
            } finally {
                return bytes;
            }
        }
Comment 1 Olivier Thomann CLA 2003-11-11 13:07:14 EST
In fact this is not a problem. You really don't need the throw clause, because
your method will never throw the exception even if you go in the catch block.
The reason is that your finally block always returns an array of bytes and
silently consume the potential IOException.
Comment 2 Olivier Thomann CLA 2003-11-11 13:10:27 EST
Looks like a duplicate of bug 22445.
Comment 3 Olivier Thomann CLA 2003-11-11 15:40:11 EST
Close as duplicate of bug 22445.

*** This bug has been marked as a duplicate of 22445 ***