Actually Tika already has the method to do this: IOUtils.closeQuietly. I think we should use it here?
While rare for IS.close() to throw an exception, if it does, it's quite awful because it masks the original exception. It seems best to be defensive? Mike McCandless http://blog.mikemccandless.com On Wed, Aug 31, 2011 at 1:25 PM, Jukka Zitting <[email protected]> wrote: > Hi, > > On Wed, Aug 31, 2011 at 6:53 PM, Uwe Schindler <[email protected]> wrote: >> For this typical try...finally code I suggest to use a pre-Java-7.0 >> workaround to make this behave more correct: If you do try...finally and >> another Exception occurs on close() in the finally block, you lose the first >> Exception. > > Such a case is certainly possible scenario, but in my experience it > practically never occurs. I've used the try { ... } finally { > stream.close(); } pattern extensively for years, and I've never seen a > case where information was lost because of this. > > So personally I consider the problem rather theoretical and would > rather opt for cleaner code that avoids the extra constructs. > > BR, > > Jukka Zitting >
