• Post Reply Bookmark Topic Watch Topic
  • New Topic

closing in finally block - some debate over what part

 
paul wheaton
Trailboss
Posts: 22063
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I turned on all sorts of warning messages in intellij. And on this block of code:



Intellij warns me to put the close into a finally block. Hmmmm .... if the constructor fails, it will throw an exception and exit the method without going into the finally block - that should be perfect because the value of "in" would be undefined (or null). So it seems weird the IJ would complain - it's usually so smart about this sort of thing.

So I try to make IJ happy and apparently, this is what it wants.




I think my version is correct and IntelliJ has made a boo boo. Or ... gasp! ... could I be wrong?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some of the IntelliJ warnings are bogus; this is one such case, in my opinion. I'd code it the way you did, and tell IntelliJ to stop warning you about nonsense like that. Note that if you review all the things that IntilliJ can warn you about, some of them are contradictory. It's assumed that different users will have different ideas about what's "right" anyway. It so happens that in this case, you and I disagree with what IntelliJ puts in as the default. So change it.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I think the inspection is wrong. But if you turn on EVERYTHING, it will mark every "*" import with a yellow line, and every single-class import! There are a number of inspections, turned off by default, that are questionable. But they all make you think, a little, anyway.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ooh, good points there, EFH!
 
paul wheaton
Trailboss
Posts: 22063
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I like the idea (ho pun intended) of this inspection. It just does it wrong.

I'm gonna e-mail serge at IJ HQ!!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!