Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Findbugs complains of streams might not get closed. LineNumberReader  RSS feed

 
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
Posts: 21088
85
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
Posts: 21088
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!