[FB-Discuss] Missed open resource?

Jason Bennett jasonab at acm.org
Fri Oct 10 14:02:51 EDT 2008


My suspicion is that passing it to the method prevents the flagging, but
Properties explicitly says that it does not close the stream.

jason


On Fri, Oct 10, 2008 at 10:53 AM, kedar mhaswade
<kedar.mhaswade at gmail.com>wrote:

> 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
>>
>>
>
> _______________________________________________
> Findbugs-discuss mailing list
> Findbugs-discuss at mcfeely.cs.umd.edu
> https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss
>
>


-- 
Jason Bennett, jasonab at acm.org
E pur si muove!
Get Firefox! - http://getfirefox.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.cs.umd.edu/pipermail/findbugs-discuss/attachments/20081010/506d97c1/attachment.html>


More information about the Findbugs-discuss mailing list