• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Findbugs complains of streams might not get closed. LineNumberReader

 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

whats wrong with this code ?

 
Rob Spoor
Sheriff
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot and its fixed !
 
Rob Spoor
Sheriff
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic