[FB-Discuss] Missed open resource?

kedar mhaswade kedar.mhaswade at gmail.com
Fri Oct 10 13:53:36 EDT 2008


Interesting! You are right, 1.3.5 does not flag this as a warning. If I just
change it thus:

            //in = this.getClass().
getClassLoader().getResourceAsStream(propertiesFile);
            in = new FileInputStream(propertiesFile);

it immediately flags the expected warnings.

So, either I/we don't understand enough about
ClassLoader.getResourceAsStream (which translates to
URL.openConnection().getInputStream()) or this is a bug.

-Kedar


On Thu, Oct 9, 2008 at 5:12 PM, Jason Bennett <jasonab at acm.org> wrote:

>
> I have some code that I believes leaves a resource hanging, but the latest
> Findbugs Eclipse plugin does not flag it.
>
> public void init() throws SearchInitializationException {
>         Properties properties = new Properties();
>         try {
>             //Load the properties from the file
>             InputStream in = loader.getResourceAsStream(propertiesFile);
>             if(in == null) {
>                 logger.fatal("Cound not locate " + propertiesFile);
>                 throw new SearchInitializationException("Cound not locate "
> + propertiesFile);
>             }
>             properties.load(in);
>             (more code that does not reference 'in')
>         } catch (IOException ex) {
>          //log and rethrow
>         }
> }
>
> As you can see, there's no finally block, and no call to ever close the
> stream, but this code is not flagged. Is the call to Properties sufficient
> to remove the flag?
>
> jason
>
> --
> Jason Bennett, jasonab at acm.org
> E pur si muove!
> Get Firefox! - http://getfirefox.com
>
> _______________________________________________
> Findbugs-discuss mailing list
> Findbugs-discuss at mcfeely.cs.umd.edu
> https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.cs.umd.edu/pipermail/findbugs-discuss/attachments/20081010/45530d19/attachment.html>


More information about the Findbugs-discuss mailing list