Bug 136509 - Warns "May be null" erroneously for variable inside try block
Summary: Warns "May be null" erroneously for variable inside try block
Status: RESOLVED DUPLICATE of bug 128962
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-12 21:00 EDT by Sarah Gerweck CLA
Modified: 2006-04-14 05:52 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sarah Gerweck CLA 2006-04-12 21:00:42 EDT
Here's a simple, correct block of code to un-gzip a file in Java. Eclipse 3.2M5a flags the `while (...)` line with a warning indicating that `is` may be null. 

It's not hard to imagine why a try block confuses Eclipse, but it's clearly never null. The compiler should analyze method calls in the try part of a try/catch just like any normal block with respect to potentially null targets.


    static void run(File srcFile, File outFile) 
           throws FileNotFoundException, IOException {
        int bytesRead;
        final byte[] buffer = new byte[BUFFER_SIZE];
        InputStream is = null;
        OutputStream os = null;
        try {
            is = new GZIPInputStream(new FileInputStream(srcFile));
            os = new FileOutputStream(outFile);
            while ((bytesRead = is.read(buffer)) > -1) {
                os.write(buffer, 0, bytesRead);
            }
        } finally {
            if (os != null) {
                os.close();
            }
            if (is != null) {
                is.close();
            }
        }
    }
Comment 1 Maxime Daniel CLA 2006-04-14 05:52:01 EDT

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