File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Findbugs complains of streams might not get closed. LineNumberReader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Findbugs complains of streams might not get closed. LineNumberReader" Watch "Findbugs complains of streams might not get closed. LineNumberReader" New topic
Author

Findbugs complains of streams might not get closed. LineNumberReader

Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

Hi Guys,

whats wrong with this code ?



Time is what we want the most, but what we use the worst. -- William Penn
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

FileReader.close may throw an IOException. If this occurs then lnReader is never closed. Note that you don't need to explicitly close both of the readers. Closing the LineNumberReader closes its backing Reader as well. Try this:
The LineNumberReader constructor throws no exceptions, so if the FileReader is created then the LineNumberReader is created as well. Except when this call is interrupted by another thread calling System.exit, or an Error (e.g. OutOfMemoryError) being thrown.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

Thanks a lot and its fixed !
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Findbugs complains of streams might not get closed. LineNumberReader