Index: solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java =================================================================== --- solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java (revision 1162371) +++ solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java (working copy) @@ -247,7 +247,7 @@ if (solrCore != null) solrCore.close(); } } - if (readersToBeClosed != null) IOUtils.closeSafely(true, readersToBeClosed); + if (readersToBeClosed != null) IOUtils.closeWhileHandlingException(readersToBeClosed); if (dirsToBeReleased != null) { for (Directory dir : dirsToBeReleased) { DirectoryFactory dirFactory = core.getDirectoryFactory(); Index: modules/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTLookup.java =================================================================== --- modules/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTLookup.java (revision 1162371) +++ modules/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTLookup.java (working copy) @@ -515,7 +515,7 @@ this.automaton = new FST(new InputStreamDataInput(is), NoOutputs.getSingleton()); cacheRootArcs(); } finally { - IOUtils.closeSafely(false, is); + IOUtils.close(is); } return true; } @@ -537,7 +537,7 @@ try { this.automaton.save(new OutputStreamDataOutput(os)); } finally { - IOUtils.closeSafely(false, os); + IOUtils.close(os); } return true; Index: modules/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java (revision 1162371) +++ modules/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java (working copy) @@ -339,7 +339,7 @@ readers[0].close(); r2.close(); outputFile.delete(); - IOUtils.closeSafely(false, dirs[0]); + IOUtils.close(dirs[0]); } private int assertReadFromDisc(TotalFacetCounts totalCounts, int prevGen, String errMsg) { @@ -405,7 +405,7 @@ outputFile.delete(); writers[0].close(); readers[0].close(); - IOUtils.closeSafely(false, dirs[0]); + IOUtils.close(dirs[0]); } /** @@ -535,7 +535,7 @@ readers[0].close(); readers[1].close(); for (Directory[] dirset : dirs) { - IOUtils.closeSafely(false, dirset); + IOUtils.close(dirset); } } Index: modules/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java (revision 1162371) +++ modules/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java (working copy) @@ -99,7 +99,7 @@ searcher.close(); iw.close(); tw.close(); - IOUtils.closeSafely(false, dirs[0]); + IOUtils.close(dirs[0]); } @Test @@ -140,7 +140,7 @@ searcher.close(); iw.close(); tw.close(); - IOUtils.closeSafely(false, dirs[0]); + IOUtils.close(dirs[0]); } @Test @@ -184,7 +184,7 @@ searcher.close(); iw.close(); tw.close(); - IOUtils.closeSafely(false, dirs[0]); + IOUtils.close(dirs[0]); } private void assertPostingListExists(String field, String text, IndexReader ir) throws IOException { @@ -230,7 +230,7 @@ searcher.close(); iw.close(); tw.close(); - IOUtils.closeSafely(false, dirs[0]); + IOUtils.close(dirs[0]); } @Test @@ -275,7 +275,7 @@ searcher.close(); iw.close(); tw.close(); - IOUtils.closeSafely(false, dirs[0]); + IOUtils.close(dirs[0]); } private Directory[][] getDirs() throws IOException { Index: modules/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCounts.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCounts.java (revision 1162371) +++ modules/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCounts.java (working copy) @@ -109,7 +109,7 @@ ++partition; } readers[0].close(); - IOUtils.closeSafely(false, dirs[0]); + IOUtils.close(dirs[0]); tmpFile.delete(); } Index: modules/facet/src/test/org/apache/lucene/facet/taxonomy/lucene/TestAddTaxonomies.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/taxonomy/lucene/TestAddTaxonomies.java (revision 1162371) +++ modules/facet/src/test/org/apache/lucene/facet/taxonomy/lucene/TestAddTaxonomies.java (working copy) @@ -247,8 +247,8 @@ } main.close(); - IOUtils.closeSafely(false, dirs); - IOUtils.closeSafely(false, copydirs); + IOUtils.close(dirs); + IOUtils.close(copydirs); } } Index: lucene/contrib/misc/src/java/org/apache/lucene/index/PKIndexSplitter.java =================================================================== --- lucene/contrib/misc/src/java/org/apache/lucene/index/PKIndexSplitter.java (revision 1162371) +++ lucene/contrib/misc/src/java/org/apache/lucene/index/PKIndexSplitter.java (working copy) @@ -89,7 +89,11 @@ createIndex(config2, dir2, reader, docsInFirstIndex, true); success = true; } finally { - IOUtils.closeSafely(!success, reader); + if (success) { + IOUtils.close(reader); + } else { + IOUtils.closeWhileHandlingException(reader); + } } } @@ -100,7 +104,11 @@ w.addIndexes(new DocumentFilteredIndexReader(reader, preserveFilter, negateFilter)); success = true; } finally { - IOUtils.closeSafely(!success, w); + if (success) { + IOUtils.close(w); + } else { + IOUtils.closeWhileHandlingException(w); + } } } Index: lucene/contrib/misc/src/java/org/apache/lucene/store/NRTCachingDirectory.java =================================================================== --- lucene/contrib/misc/src/java/org/apache/lucene/store/NRTCachingDirectory.java (revision 1162371) +++ lucene/contrib/misc/src/java/org/apache/lucene/store/NRTCachingDirectory.java (working copy) @@ -280,7 +280,7 @@ in = cache.openInput(fileName, context); in.copyBytes(out, in.length()); } finally { - IOUtils.closeSafely(false, in, out); + IOUtils.close(in, out); } synchronized(this) { cache.deleteFile(fileName); Index: lucene/src/test/org/apache/lucene/search/TestTermVectors.java =================================================================== --- lucene/src/test/org/apache/lucene/search/TestTermVectors.java (revision 1162371) +++ lucene/src/test/org/apache/lucene/search/TestTermVectors.java (working copy) @@ -541,7 +541,7 @@ verifyIndex(target); - IOUtils.closeSafely(false, target, input[0], input[1]); + IOUtils.close(target, input[0], input[1]); } public void testOptimizeAddIndexesReader() throws Exception { @@ -562,7 +562,7 @@ writer.close(); verifyIndex(target); - IOUtils.closeSafely(false, target, input[0], input[1]); + IOUtils.close(target, input[0], input[1]); } } Index: lucene/src/test/org/apache/lucene/util/TestIOUtils.java =================================================================== --- lucene/src/test/org/apache/lucene/util/TestIOUtils.java (revision 1162371) +++ lucene/src/test/org/apache/lucene/util/TestIOUtils.java (working copy) @@ -59,7 +59,7 @@ // test with prior exception try { final TestException t = new TestException(); - IOUtils.closeSafely(t, new BrokenCloseable(1), new BrokenCloseable(2)); + IOUtils.closeWhileHandlingException(t, new BrokenCloseable(1), new BrokenCloseable(2)); } catch (TestException e1) { assertEquals("BASE-EXCEPTION", e1.getMessage()); final StringWriter sw = new StringWriter(); @@ -83,7 +83,7 @@ // test without prior exception try { - IOUtils.closeSafely((TestException) null, new BrokenCloseable(1), new BrokenCloseable(2)); + IOUtils.closeWhileHandlingException((TestException) null, new BrokenCloseable(1), new BrokenCloseable(2)); } catch (TestException e1) { fail("TestException should not be thrown here"); } catch (IOException e2) { Index: lucene/src/java/org/apache/lucene/index/FieldsReader.java =================================================================== --- lucene/src/java/org/apache/lucene/index/FieldsReader.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/FieldsReader.java (working copy) @@ -174,9 +174,9 @@ public final void close() throws IOException { if (!closed) { if (isOriginal) { - IOUtils.closeSafely(false, fieldsStream, indexStream, fieldsStreamTL, cloneableFieldsStream, cloneableIndexStream); + IOUtils.close(fieldsStream, indexStream, fieldsStreamTL, cloneableFieldsStream, cloneableIndexStream); } else { - IOUtils.closeSafely(false, fieldsStream, indexStream, fieldsStreamTL); + IOUtils.close(fieldsStream, indexStream, fieldsStreamTL); } closed = true; } Index: lucene/src/java/org/apache/lucene/index/FieldsWriter.java =================================================================== --- lucene/src/java/org/apache/lucene/index/FieldsWriter.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/FieldsWriter.java (working copy) @@ -111,7 +111,7 @@ void close() throws IOException { if (directory != null) { try { - IOUtils.closeSafely(false, fieldsStream, indexStream); + IOUtils.close(fieldsStream, indexStream); } finally { fieldsStream = indexStream = null; } Index: lucene/src/java/org/apache/lucene/index/MultiPerDocValues.java =================================================================== --- lucene/src/java/org/apache/lucene/index/MultiPerDocValues.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/MultiPerDocValues.java (working copy) @@ -152,7 +152,7 @@ } public void close() throws IOException { - IOUtils.closeSafely(false, this.subs); + IOUtils.close(this.subs); } @Override Index: lucene/src/java/org/apache/lucene/index/values/IntsImpl.java =================================================================== --- lucene/src/java/org/apache/lucene/index/values/IntsImpl.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/values/IntsImpl.java (working copy) @@ -131,7 +131,7 @@ } finally { if (!success) { - IOUtils.closeSafely(true, datOut); + IOUtils.closeWhileHandlingException(datOut); } } } @@ -152,7 +152,11 @@ } success = true; } finally { - IOUtils.closeSafely(!success, datOut); + if (success) { + IOUtils.close(datOut); + } else { + IOUtils.closeWhileHandlingException(datOut); + } array.clear(); } } @@ -286,7 +290,7 @@ success = true; } finally { if (!success) { - IOUtils.closeSafely(true, datIn); + IOUtils.closeWhileHandlingException(datIn); } } } @@ -301,7 +305,11 @@ datOut.copyBytes(indexInput, bytesPerValue(type) * numDocs); success = true; } finally { - IOUtils.closeSafely(!success, indexInput); + if (success) { + IOUtils.close(indexInput); + } else { + IOUtils.closeWhileHandlingException(indexInput); + } } return numDocs; } @@ -323,7 +331,7 @@ return source; } finally { if (!success) { - IOUtils.closeSafely(true, input, datIn); + IOUtils.closeWhileHandlingException(input, datIn); } } } @@ -345,7 +353,7 @@ return inst; } finally { if (!success) { - IOUtils.closeSafely(true, input); + IOUtils.closeWhileHandlingException(input); } } } Index: lucene/src/java/org/apache/lucene/index/values/VarSortedBytesImpl.java =================================================================== --- lucene/src/java/org/apache/lucene/index/values/VarSortedBytesImpl.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/values/VarSortedBytesImpl.java (working copy) @@ -124,7 +124,11 @@ } success = true; } finally { - IOUtils.closeSafely(!success, datOut); + if (success) { + IOUtils.close(datOut); + } else { + IOUtils.closeWhileHandlingException(datOut); + } hash.close(); } final IndexOutput idxOut = getIndexOut(); @@ -161,7 +165,11 @@ bytesUsed.addAndGet((-docToEntry.length) * RamUsageEstimator.NUM_BYTES_INT); docToEntry = null; - IOUtils.closeSafely(!success, idxOut); + if (success) { + IOUtils.close(idxOut); + } else { + IOUtils.closeWhileHandlingException(idxOut); + } } } } Index: lucene/src/java/org/apache/lucene/index/values/FixedSortedBytesImpl.java =================================================================== --- lucene/src/java/org/apache/lucene/index/values/FixedSortedBytesImpl.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/values/FixedSortedBytesImpl.java (working copy) @@ -126,7 +126,11 @@ } success = true; } finally { - IOUtils.closeSafely(!success, datOut); + if (success) { + IOUtils.close(datOut); + } else { + IOUtils.closeWhileHandlingException(datOut); + } hash.close(); } final IndexOutput idxOut = getIndexOut(); @@ -159,7 +163,11 @@ } w.finish(); } finally { - IOUtils.closeSafely(!success, idxOut); + if (success) { + IOUtils.close(idxOut); + } else { + IOUtils.closeWhileHandlingException(idxOut); + } bytesUsed.addAndGet((-docToEntry.length) * RamUsageEstimator.NUM_BYTES_INT); docToEntry = null; Index: lucene/src/java/org/apache/lucene/index/values/Bytes.java =================================================================== --- lucene/src/java/org/apache/lucene/index/values/Bytes.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/values/Bytes.java (working copy) @@ -368,7 +368,7 @@ success = true; } finally { if (!success) { - IOUtils.closeSafely(true, datOut); + IOUtils.closeWhileHandlingException(datOut); } } } @@ -386,7 +386,7 @@ success = true; } finally { if (!success) { - IOUtils.closeSafely(true, idxOut); + IOUtils.closeWhileHandlingException(idxOut); } } return idxOut; Index: lucene/src/java/org/apache/lucene/index/values/VarStraightBytesImpl.java =================================================================== --- lucene/src/java/org/apache/lucene/index/values/VarStraightBytesImpl.java (revision 1162375) +++ lucene/src/java/org/apache/lucene/index/values/VarStraightBytesImpl.java (working copy) @@ -128,13 +128,13 @@ address += numDataBytes; // this is the address after all addr pointers are updated iter.close(); } finally { - IOUtils.closeSafely(false, cloneIdx); + IOUtils.close(cloneIdx); } final IndexInput cloneData = reader.cloneData(); try { datOut.copyBytes(cloneData, numDataBytes); } finally { - IOUtils.closeSafely(false, cloneData); + IOUtils.close(cloneData); } } else { super.merge(state); @@ -142,7 +142,7 @@ success = true; } finally { if (!success) { - IOUtils.closeSafely(!success, datOut); + IOUtils.closeWhileHandlingException(datOut); } } } @@ -174,7 +174,11 @@ } success = true; } finally { - IOUtils.closeSafely(!success, datOut); + if (success) { + IOUtils.close(datOut); + } else { + IOUtils.closeWhileHandlingException(datOut); + } pool.dropBuffersAndReset(); } @@ -204,7 +208,11 @@ bytesUsed.addAndGet(-(docToAddress.length) * RamUsageEstimator.NUM_BYTES_INT); docToAddress = null; - IOUtils.closeSafely(!success, idxOut); + if (success) { + IOUtils.close(idxOut); + } else { + IOUtils.closeWhileHandlingException(idxOut); + } } } Index: lucene/src/java/org/apache/lucene/index/values/VarDerefBytesImpl.java =================================================================== --- lucene/src/java/org/apache/lucene/index/values/VarDerefBytesImpl.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/values/VarDerefBytesImpl.java (working copy) @@ -184,7 +184,11 @@ success = true; } finally { hash.close(); - IOUtils.closeSafely(!success, datOut); + if (success) { + IOUtils.close(datOut); + } else { + IOUtils.closeWhileHandlingException(datOut); + } } final IndexOutput idxOut = getIndexOut(); @@ -211,7 +215,11 @@ w.finish(); success = true; } finally { - IOUtils.closeSafely(!success,idxOut); + if (success) { + IOUtils.close(idxOut); + } else { + IOUtils.closeWhileHandlingException(idxOut); + } bytesUsed.addAndGet(RamUsageEstimator.NUM_BYTES_INT * (-docToAddress.length)); docToAddress = null; Index: lucene/src/java/org/apache/lucene/index/values/Floats.java =================================================================== --- lucene/src/java/org/apache/lucene/index/values/Floats.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/values/Floats.java (working copy) @@ -102,7 +102,7 @@ success = true; } finally { if (!success) { - IOUtils.closeSafely(true, datOut); + IOUtils.closeWhileHandlingException(datOut); } } } @@ -214,11 +214,13 @@ bytesUsed.addAndGet(-(RamUsageEstimator.NUM_BYTES_INT * ((values.length)))); values = null; - IOUtils.closeSafely(!success, datOut); + if (success) { + IOUtils.close(datOut); + } else { + IOUtils.closeWhileHandlingException(datOut); + } } } - - } // Writes 8 bytes (double) per value @@ -275,7 +277,11 @@ bytesUsed.addAndGet(-(RamUsageEstimator.NUM_BYTES_LONG * ((values.length)))); values = null; - IOUtils.closeSafely(!success, datOut); + if (success) { + IOUtils.close(datOut); + } else { + IOUtils.closeWhileHandlingException(datOut); + } } } } Index: lucene/src/java/org/apache/lucene/index/values/FixedStraightBytesImpl.java =================================================================== --- lucene/src/java/org/apache/lucene/index/values/FixedStraightBytesImpl.java (revision 1162375) +++ lucene/src/java/org/apache/lucene/index/values/FixedStraightBytesImpl.java (working copy) @@ -123,7 +123,7 @@ try { datOut.copyBytes(cloneData, size * maxDocs); } finally { - IOUtils.closeSafely(false, cloneData); + IOUtils.close(cloneData); } lastDocID += maxDocs; @@ -133,7 +133,7 @@ success = true; } finally { if (!success) { - IOUtils.closeSafely(!success, datOut); + IOUtils.closeWhileHandlingException(datOut); } } } @@ -194,7 +194,11 @@ success = true; } finally { pool.dropBuffersAndReset(); - IOUtils.closeSafely(!success, datOut); + if (success) { + IOUtils.close(datOut); + } else { + IOUtils.closeWhileHandlingException(datOut); + } } } } @@ -231,7 +235,7 @@ data = new byte[maxDoc]; datIn.readBytes(data, 0, data.length, false); } finally { - IOUtils.closeSafely(false, datIn); + IOUtils.close(datIn); } } Index: lucene/src/java/org/apache/lucene/index/values/FixedDerefBytesImpl.java =================================================================== --- lucene/src/java/org/apache/lucene/index/values/FixedDerefBytesImpl.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/values/FixedDerefBytesImpl.java (working copy) @@ -112,7 +112,11 @@ } success = true; } finally { - IOUtils.closeSafely(!success, datOut); + if (success) { + IOUtils.close(datOut); + } else { + IOUtils.closeWhileHandlingException(datOut); + } hash.close(); } success = false; @@ -134,7 +138,11 @@ w.finish(); success = true; } finally { - IOUtils.closeSafely(!success, idxOut); + if (success) { + IOUtils.close(idxOut); + } else { + IOUtils.closeWhileHandlingException(idxOut); + } bytesUsed .addAndGet((-docToID.length) * RamUsageEstimator.NUM_BYTES_INT); docToID = null; Index: lucene/src/java/org/apache/lucene/index/SegmentInfos.java =================================================================== --- lucene/src/java/org/apache/lucene/index/SegmentInfos.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/SegmentInfos.java (working copy) @@ -331,7 +331,7 @@ if (!success) { // We hit an exception above; try to close the file // but suppress any exception: - IOUtils.closeSafely(true, segnOutput); + IOUtils.closeWhileHandlingException(segnOutput); try { // Try not to leave a truncated segments_N file in // the index: Index: lucene/src/java/org/apache/lucene/index/SegmentMerger.java =================================================================== --- lucene/src/java/org/apache/lucene/index/SegmentMerger.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/SegmentMerger.java (working copy) @@ -573,7 +573,11 @@ slices.toArray(ReaderUtil.Slice.EMPTY_ARRAY))); success = true; } finally { - IOUtils.closeSafely(!success, consumer); + if (success) { + IOUtils.close(consumer); + } else { + IOUtils.closeWhileHandlingException(consumer); + } } } @@ -602,7 +606,11 @@ docsConsumer.merge(mergeState, multiPerDocValues); success = true; } finally { - IOUtils.closeSafely(!success, docsConsumer); + if (success) { + IOUtils.close(docsConsumer); + } else { + IOUtils.closeWhileHandlingException(docsConsumer); + } } } /* don't close the perDocProducers here since they are private segment producers @@ -654,7 +662,11 @@ } success = true; } finally { - IOUtils.closeSafely(!success, output); + if (success) { + IOUtils.close(output); + } else { + IOUtils.closeWhileHandlingException(output); + } } } } Index: lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java =================================================================== --- lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java (revision 1162375) +++ lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java (working copy) @@ -87,7 +87,7 @@ consumers.finish(state.numDocs); }; // close perDocConsumer during flush to ensure all files are flushed due to PerCodec CFS - IOUtils.closeSafely(false, perDocConsumers.values()); + IOUtils.close(perDocConsumers.values()); } @Override @@ -108,7 +108,7 @@ } } try { - IOUtils.closeSafely(true, perDocConsumers.values()); + IOUtils.closeWhileHandlingException(perDocConsumers.values()); // TODO add abort to PerDocConsumer! } catch (IOException e) { // ignore on abort! Index: lucene/src/java/org/apache/lucene/index/FreqProxTermsWriter.java =================================================================== --- lucene/src/java/org/apache/lucene/index/FreqProxTermsWriter.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/FreqProxTermsWriter.java (working copy) @@ -105,7 +105,11 @@ } success = true; } finally { - IOUtils.closeSafely(!success, consumer); + if (success) { + IOUtils.close(consumer); + } else { + IOUtils.closeWhileHandlingException(consumer); + } } } Index: lucene/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java =================================================================== --- lucene/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java (working copy) @@ -57,7 +57,7 @@ fill(state.numDocs); assert state.segmentName != null; String idxName = IndexFileNames.segmentFileName(state.segmentName, "", IndexFileNames.VECTORS_INDEX_EXTENSION); - IOUtils.closeSafely(false, tvx, tvf, tvd); + IOUtils.close(tvx, tvf, tvd); tvx = tvd = tvf = null; if (4+((long) state.numDocs)*16 != state.directory.fileLength(idxName)) { throw new RuntimeException("after flush: tvx size mismatch: " + state.numDocs + " docs vs " + state.directory.fileLength(idxName) + " length in bytes of " + idxName + " file exists?=" + state.directory.fileExists(idxName)); @@ -107,7 +107,7 @@ success = true; } finally { if (!success) { - IOUtils.closeSafely(true, tvx, tvd, tvf); + IOUtils.closeWhileHandlingException(tvx, tvd, tvf); } } @@ -161,7 +161,7 @@ public void abort() { hasVectors = false; try { - IOUtils.closeSafely(true, tvx, tvd, tvf); + IOUtils.closeWhileHandlingException(tvx, tvd, tvf); } catch (IOException e) { // cannot happen since we suppress exceptions throw new RuntimeException(e); Index: lucene/src/java/org/apache/lucene/index/PerFieldCodecWrapper.java =================================================================== --- lucene/src/java/org/apache/lucene/index/PerFieldCodecWrapper.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/PerFieldCodecWrapper.java (working copy) @@ -75,7 +75,7 @@ success = true; } finally { if (!success) { - IOUtils.closeSafely(true, consumers); + IOUtils.closeWhileHandlingException(consumers); } } } @@ -90,7 +90,7 @@ @Override public void close() throws IOException { - IOUtils.closeSafely(false, consumers); + IOUtils.close(consumers); } } @@ -123,7 +123,7 @@ // If we hit exception (eg, IOE because writer was // committing, or, for any other reason) we must // go back and close all FieldsProducers we opened: - IOUtils.closeSafely(true, producers.values()); + IOUtils.closeWhileHandlingException(producers.values()); } } } @@ -172,7 +172,7 @@ @Override public void close() throws IOException { - IOUtils.closeSafely(false, codecs.values()); + IOUtils.close(codecs.values()); } } @@ -230,7 +230,7 @@ success = true; } finally { if (!success) { - IOUtils.closeSafely(true, producers.values()); + IOUtils.closeWhileHandlingException(producers.values()); } } } @@ -249,7 +249,7 @@ } public void close() throws IOException { - IOUtils.closeSafely(false, codecs.values()); + IOUtils.close(codecs.values()); } } @@ -266,7 +266,7 @@ } public void close() throws IOException { - IOUtils.closeSafely(false, consumers); + IOUtils.close(consumers); } @Override Index: lucene/src/java/org/apache/lucene/index/TermVectorsReader.java =================================================================== --- lucene/src/java/org/apache/lucene/index/TermVectorsReader.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/TermVectorsReader.java (working copy) @@ -193,7 +193,7 @@ } public void close() throws IOException { - IOUtils.closeSafely(false, tvx, tvd, tvf); + IOUtils.close(tvx, tvd, tvf); } /** Index: lucene/src/java/org/apache/lucene/index/IndexWriter.java =================================================================== --- lucene/src/java/org/apache/lucene/index/IndexWriter.java (revision 1162375) +++ lucene/src/java/org/apache/lucene/index/IndexWriter.java (working copy) @@ -2270,7 +2270,7 @@ } catch(IOException ex) { prior = ex; } finally { - IOUtils.closeSafely(prior, cfsDir); + IOUtils.closeWhileHandlingException(prior, cfsDir); } // Perform the merge @@ -2606,7 +2606,7 @@ } } } finally { - IOUtils.closeSafely(false, cfsdir); + IOUtils.close(cfsdir); } info.dir = directory; Index: lucene/src/java/org/apache/lucene/index/TermVectorsWriter.java =================================================================== --- lucene/src/java/org/apache/lucene/index/TermVectorsWriter.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/TermVectorsWriter.java (working copy) @@ -45,7 +45,7 @@ success = true; } finally { if (!success) { - IOUtils.closeSafely(true, tvx, tvd, tvf); + IOUtils.closeWhileHandlingException(tvx, tvd, tvf); } } @@ -194,6 +194,6 @@ final void close() throws IOException { // make an effort to close all streams we can but remember and re-throw // the first exception encountered in this process - IOUtils.closeSafely(false, tvx, tvd, tvf); + IOUtils.close(tvx, tvd, tvf); } } Index: lucene/src/java/org/apache/lucene/index/codecs/BlockTermsWriter.java =================================================================== --- lucene/src/java/org/apache/lucene/index/codecs/BlockTermsWriter.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/codecs/BlockTermsWriter.java (working copy) @@ -88,7 +88,7 @@ success = true; } finally { if (!success) { - IOUtils.closeSafely(true, out); + IOUtils.closeWhileHandlingException(out); } } } @@ -138,7 +138,7 @@ } writeTrailer(dirStart); } finally { - IOUtils.closeSafely(false, out, postingsWriter, termsIndexWriter); + IOUtils.close(out, postingsWriter, termsIndexWriter); } } Index: lucene/src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosWriter.java =================================================================== --- lucene/src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosWriter.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosWriter.java (working copy) @@ -74,7 +74,7 @@ return out; } finally { if (!success) { - IOUtils.closeSafely(true, out); + IOUtils.closeWhileHandlingException(out); } } } Index: lucene/src/java/org/apache/lucene/index/codecs/FixedGapTermsIndexReader.java =================================================================== --- lucene/src/java/org/apache/lucene/index/codecs/FixedGapTermsIndexReader.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/codecs/FixedGapTermsIndexReader.java (working copy) @@ -111,7 +111,9 @@ } success = true; } finally { - if (!success) IOUtils.closeSafely(true, in); + if (!success) { + IOUtils.closeWhileHandlingException(in); + } if (indexDivisor > 0) { in.close(); in = null; Index: lucene/src/java/org/apache/lucene/index/codecs/FixedGapTermsIndexWriter.java =================================================================== --- lucene/src/java/org/apache/lucene/index/codecs/FixedGapTermsIndexWriter.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/codecs/FixedGapTermsIndexWriter.java (working copy) @@ -67,7 +67,7 @@ success = true; } finally { if (!success) { - IOUtils.closeSafely(true, out); + IOUtils.closeWhileHandlingException(out); } } } @@ -240,7 +240,11 @@ writeTrailer(dirStart); success = true; } finally { - IOUtils.closeSafely(!success, out); + if (success) { + IOUtils.close(out); + } else { + IOUtils.closeWhileHandlingException(out); + } } } Index: lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsWriter.java =================================================================== --- lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsWriter.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsWriter.java (working copy) @@ -150,7 +150,7 @@ success = true; } finally { if (!success) { - IOUtils.closeSafely(true, docOut, skipOut, freqOut, posOut, payloadOut); + IOUtils.closeWhileHandlingException(docOut, skipOut, freqOut, posOut, payloadOut); } } @@ -389,7 +389,7 @@ @Override public void close() throws IOException { - IOUtils.closeSafely(false, docOut, skipOut, freqOut, posOut, payloadOut); + IOUtils.close(docOut, skipOut, freqOut, posOut, payloadOut); } public static void getExtensions(Set extensions) { Index: lucene/src/java/org/apache/lucene/index/codecs/BlockTreeTermsReader.java =================================================================== --- lucene/src/java/org/apache/lucene/index/codecs/BlockTreeTermsReader.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/codecs/BlockTreeTermsReader.java (working copy) @@ -160,7 +160,7 @@ success = true; } finally { if (!success) { - IOUtils.closeSafely(true, indexIn, this); + IOUtils.closeWhileHandlingException(indexIn, this); } else if (indexDivisor != -1) { indexIn.close(); } @@ -194,7 +194,7 @@ @Override public void close() throws IOException { try { - IOUtils.closeSafely(false, in, postingsReader); + IOUtils.close(in, postingsReader); } finally { for(FieldReader field : fields.values()) { field.close(); Index: lucene/src/java/org/apache/lucene/index/codecs/VariableGapTermsIndexWriter.java =================================================================== --- lucene/src/java/org/apache/lucene/index/codecs/VariableGapTermsIndexWriter.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/codecs/VariableGapTermsIndexWriter.java (working copy) @@ -168,7 +168,7 @@ success = true; } finally { if (!success) { - IOUtils.closeSafely(true, out); + IOUtils.closeWhileHandlingException(out); } } } Index: lucene/src/java/org/apache/lucene/index/codecs/BlockTreeTermsWriter.java =================================================================== --- lucene/src/java/org/apache/lucene/index/codecs/BlockTreeTermsWriter.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/codecs/BlockTreeTermsWriter.java (working copy) @@ -171,7 +171,7 @@ success = true; } finally { if (!success) { - IOUtils.closeSafely(true, out, indexOut); + IOUtils.closeWhileHandlingException(out, indexOut); } } this.indexOut = indexOut; @@ -937,7 +937,7 @@ } catch (IOException ioe2) { ioe = ioe2; } finally { - IOUtils.closeSafely(ioe, out, indexOut, postingsWriter); + IOUtils.closeWhileHandlingException(ioe, out, indexOut, postingsWriter); } } } Index: lucene/src/java/org/apache/lucene/index/codecs/DefaultDocValuesProducer.java =================================================================== --- lucene/src/java/org/apache/lucene/index/codecs/DefaultDocValuesProducer.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/codecs/DefaultDocValuesProducer.java (working copy) @@ -189,7 +189,7 @@ } else { toClose = closeables; } - IOUtils.closeSafely(false, toClose); + IOUtils.close(toClose); } @Override Index: lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java =================================================================== --- lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java (working copy) @@ -122,7 +122,7 @@ synchronized void decRef() throws IOException { if (ref.decrementAndGet() == 0) { - IOUtils.closeSafely(false, fields, perDocProducer, termVectorsReaderOrig, + IOUtils.close(fields, perDocProducer, termVectorsReaderOrig, fieldsReaderOrig, cfsReader, storeCFSReader); // Now, notify any ReaderFinished listeners: if (owner != null) { Index: lucene/src/java/org/apache/lucene/index/NormsWriter.java =================================================================== --- lucene/src/java/org/apache/lucene/index/NormsWriter.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/index/NormsWriter.java (working copy) @@ -88,7 +88,11 @@ } success = true; } finally { - IOUtils.closeSafely(!success, normsOut); + if (success) { + IOUtils.close(normsOut); + } else { + IOUtils.closeWhileHandlingException(normsOut); + } } } Index: lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java =================================================================== --- lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java (revision 1162375) +++ lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java (working copy) @@ -68,7 +68,7 @@ success = true; } finally { if (!success) { - IOUtils.closeSafely(true, handle); + IOUtils.closeWhileHandlingException(handle); } } this.isOpen = true; @@ -112,7 +112,7 @@ } return mapping; } finally { - IOUtils.closeSafely(false, input); + IOUtils.close(input); } } else { // TODO remove once 3.x is not supported anymore @@ -121,7 +121,11 @@ success = true; return mapping; } finally { - IOUtils.closeSafely(!success, stream); + if (success) { + IOUtils.close(stream); + } else { + IOUtils.closeWhileHandlingException(stream); + } } } @@ -196,7 +200,7 @@ assert openForWrite; writer.close(); } else { - IOUtils.closeSafely(false, handle); + IOUtils.close(handle); } } Index: lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java =================================================================== --- lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java (working copy) @@ -117,7 +117,7 @@ success = true; } finally { if (!success) { - IOUtils.closeSafely(true, dataOut); + IOUtils.closeWhileHandlingException(dataOut); } } } @@ -157,7 +157,7 @@ } catch (IOException e) { priorException = e; } finally { - IOUtils.closeSafely(priorException, dataOut); + IOUtils.closeWhileHandlingException(priorException, dataOut); } try { entryTableOut = directory.createOutput(entryTableName, IOContext.DEFAULT); @@ -165,7 +165,7 @@ } catch (IOException e) { priorException = e; } finally { - IOUtils.closeSafely(priorException, entryTableOut); + IOUtils.closeWhileHandlingException(priorException, entryTableOut); } } @@ -205,13 +205,14 @@ success = true; return length; } finally { - IOUtils.closeSafely(!success, is); if (success) { + IOUtils.close(is); // copy successful - delete file fileEntry.dir.deleteFile(fileEntry.file); + } else { + IOUtils.closeWhileHandlingException(is); } } - } protected void writeEntryTable(Collection entries, Index: lucene/src/java/org/apache/lucene/store/Directory.java =================================================================== --- lucene/src/java/org/apache/lucene/store/Directory.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/store/Directory.java (working copy) @@ -204,7 +204,7 @@ } catch (IOException ioe) { priorException = ioe; } finally { - IOUtils.closeSafely(priorException, os, is); + IOUtils.closeWhileHandlingException(priorException, os, is); } } Index: lucene/src/java/org/apache/lucene/util/IOUtils.java =================================================================== --- lucene/src/java/org/apache/lucene/util/IOUtils.java (revision 1162371) +++ lucene/src/java/org/apache/lucene/util/IOUtils.java (working copy) @@ -49,7 +49,7 @@ * @param priorException null or an exception that will be rethrown after method completion * @param objects objects to call close() on */ - public static void closeSafely(E priorException, Closeable... objects) throws E, IOException { + public static void closeWhileHandlingException(E priorException, Closeable... objects) throws E, IOException { Throwable th = null; for (Closeable object : objects) { @@ -76,7 +76,7 @@ } /** @see #closeSafely(Exception, Closeable...) */ - public static void closeSafely(E priorException, Iterable objects) throws E, IOException { + public static void closeWhileHandlingException(E priorException, Iterable objects) throws E, IOException { Throwable th = null; for (Closeable object : objects) { @@ -103,18 +103,16 @@ } /** - * Closes all given Closeables, suppressing all thrown exceptions. - * Some of the Closeables may be null, they are ignored. After - * everything is closed, and if {@code suppressExceptions} is {@code false}, - * method either throws the first of suppressed exceptions, or completes - * normally. + * Closes all given Closeables. Some of the + * Closeables may be null; they are + * ignored. After everything is closed, the method either + * throws the first exception it hit while closing, or + * completes normally if there were no exceptions. * - * @param suppressExceptions - * if true then exceptions that occur during close() are suppressed * @param objects * objects to call close() on */ - public static void closeSafely(boolean suppressExceptions, Closeable... objects) throws IOException { + public static void close(Closeable... objects) throws IOException { Throwable th = null; for (Closeable object : objects) { @@ -124,12 +122,13 @@ } } catch (Throwable t) { addSuppressed(th, t); - if (th == null) + if (th == null) { th = t; + } } } - if (th != null && !suppressExceptions) { + if (th != null) { if (th instanceof IOException) throw (IOException) th; if (th instanceof RuntimeException) throw (RuntimeException) th; if (th instanceof Error) throw (Error) th; @@ -138,9 +137,9 @@ } /** - * @see #closeSafely(boolean, Closeable...) + * @see #close(Closeable...) */ - public static void closeSafely(boolean suppressExceptions, Iterable objects) throws IOException { + public static void close(Iterable objects) throws IOException { Throwable th = null; for (Closeable object : objects) { @@ -150,19 +149,52 @@ } } catch (Throwable t) { addSuppressed(th, t); - if (th == null) + if (th == null) { th = t; + } } } - if (th != null && !suppressExceptions) { + if (th != null) { if (th instanceof IOException) throw (IOException) th; if (th instanceof RuntimeException) throw (RuntimeException) th; if (th instanceof Error) throw (Error) th; throw new RuntimeException(th); } } + + /** + * Closes all given Closeables, suppressing all thrown exceptions. + * Some of the Closeables may be null, they are ignored. + * + * @param objects + * objects to call close() on + */ + public static void closeWhileHandlingException(Closeable... objects) throws IOException { + for (Closeable object : objects) { + try { + if (object != null) { + object.close(); + } + } catch (Throwable t) { + } + } + } + /** + * @see #closeSafely(boolean, Closeable...) + */ + public static void closeWhileHandlingException(Iterable objects) throws IOException { + for (Closeable object : objects) { + try { + if (object != null) { + object.close(); + } + } catch (Throwable t) { + } + } + } + /** This reflected {@link Method} is {@code null} before Java 7 */ private static final Method SUPPRESS_METHOD; static { Index: lucene/src/test-framework/org/apache/lucene/index/codecs/mockintblock/MockVariableIntBlockCodec.java =================================================================== --- lucene/src/test-framework/org/apache/lucene/index/codecs/mockintblock/MockVariableIntBlockCodec.java (revision 1162371) +++ lucene/src/test-framework/org/apache/lucene/index/codecs/mockintblock/MockVariableIntBlockCodec.java (working copy) @@ -142,7 +142,7 @@ return ret; } finally { if (!success) { - IOUtils.closeSafely(true, out); + IOUtils.closeWhileHandlingException(out); } } } Index: lucene/src/test-framework/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockCodec.java =================================================================== --- lucene/src/test-framework/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockCodec.java (revision 1162371) +++ lucene/src/test-framework/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockCodec.java (working copy) @@ -119,7 +119,7 @@ return ret; } finally { if (!success) { - IOUtils.closeSafely(true, out); + IOUtils.closeWhileHandlingException(out); } } } Index: lucene/src/test-framework/org/apache/lucene/index/codecs/mocksep/MockSingleIntIndexOutput.java =================================================================== --- lucene/src/test-framework/org/apache/lucene/index/codecs/mocksep/MockSingleIntIndexOutput.java (revision 1162371) +++ lucene/src/test-framework/org/apache/lucene/index/codecs/mocksep/MockSingleIntIndexOutput.java (working copy) @@ -44,7 +44,7 @@ success = true; } finally { if (!success) { - IOUtils.closeSafely(true, out); + IOUtils.closeWhileHandlingException(out); } } } Index: lucene/src/test-framework/org/apache/lucene/index/codecs/preflexrw/TermInfosWriter.java =================================================================== --- lucene/src/test-framework/org/apache/lucene/index/codecs/preflexrw/TermInfosWriter.java (revision 1162371) +++ lucene/src/test-framework/org/apache/lucene/index/codecs/preflexrw/TermInfosWriter.java (working copy) @@ -98,7 +98,7 @@ } finally { if (!success) { try { - IOUtils.closeSafely(true, output); + IOUtils.closeWhileHandlingException(output); } catch (IOException e) { // cannot happen since we suppress exceptions throw new RuntimeException(e); @@ -139,7 +139,7 @@ } finally { if (!success) { try { - IOUtils.closeSafely(true, output); + IOUtils.closeWhileHandlingException(output); } catch (IOException e) { // cannot happen since we suppress exceptions throw new RuntimeException(e); Index: lucene/src/test-framework/org/apache/lucene/index/codecs/preflexrw/PreFlexFieldsWriter.java =================================================================== --- lucene/src/test-framework/org/apache/lucene/index/codecs/preflexrw/PreFlexFieldsWriter.java (revision 1162371) +++ lucene/src/test-framework/org/apache/lucene/index/codecs/preflexrw/PreFlexFieldsWriter.java (working copy) @@ -78,7 +78,7 @@ @Override public void close() throws IOException { - IOUtils.closeSafely(false, termsOut, freqOut, proxOut); + IOUtils.close(termsOut, freqOut, proxOut); } private class PreFlexTermsWriter extends TermsConsumer {