Index: lucene/core/src/java/org/apache/lucene/store/CompoundFileDirectory.java =================================================================== --- lucene/core/src/java/org/apache/lucene/store/CompoundFileDirectory.java (revision 1356034) +++ lucene/core/src/java/org/apache/lucene/store/CompoundFileDirectory.java (working copy) @@ -127,12 +127,13 @@ /** Helper method that reads CFS entries from an input stream */ private static final Map readEntries( IndexInputSlicer handle, Directory dir, String name) throws IOException { + IndexInput input = null; // read the first VInt. If it is negative, it's the version number // otherwise it's the count (pre-3.1 indexes) final IndexInput stream = handle.openFullSlice(); - final Map mapping; boolean success = false; try { + final Map mapping; final int firstInt = stream.readVInt(); // impossible for 3.0 to have 63 files in a .cfs, CFS writer was not visible // and separate norms/etc are outside of cfs. @@ -148,27 +149,20 @@ } CodecUtil.checkHeaderNoMagic(stream, CompoundFileWriter.DATA_CODEC, CompoundFileWriter.VERSION_START, CompoundFileWriter.VERSION_START); - IndexInput input = null; - try { - final String entriesFileName = IndexFileNames.segmentFileName( - IndexFileNames.stripExtension(name), "", - IndexFileNames.COMPOUND_FILE_ENTRIES_EXTENSION); - input = dir.openInput(entriesFileName, IOContext.READONCE); - CodecUtil.checkHeader(input, CompoundFileWriter.ENTRY_CODEC, CompoundFileWriter.VERSION_START, CompoundFileWriter.VERSION_START); - final int numEntries = input.readVInt(); - mapping = new HashMap( - numEntries); - for (int i = 0; i < numEntries; i++) { - final FileEntry fileEntry = new FileEntry(); - final String id = input.readString(); - assert !mapping.containsKey(id): "id=" + id + " was written multiple times in the CFS"; - mapping.put(id, fileEntry); - fileEntry.offset = input.readLong(); - fileEntry.length = input.readLong(); - } - return mapping; - } finally { - IOUtils.close(input); + final String entriesFileName = IndexFileNames.segmentFileName( + IndexFileNames.stripExtension(name), "", + IndexFileNames.COMPOUND_FILE_ENTRIES_EXTENSION); + input = dir.openInput(entriesFileName, IOContext.READONCE); + CodecUtil.checkHeader(input, CompoundFileWriter.ENTRY_CODEC, CompoundFileWriter.VERSION_START, CompoundFileWriter.VERSION_START); + final int numEntries = input.readVInt(); + mapping = new HashMap(numEntries); + for (int i = 0; i < numEntries; i++) { + final FileEntry fileEntry = new FileEntry(); + final String id = input.readString(); + assert !mapping.containsKey(id): "id=" + id + " was written multiple times in the CFS"; + mapping.put(id, fileEntry); + fileEntry.offset = input.readLong(); + fileEntry.length = input.readLong(); } } else { // TODO remove once 3.x is not supported anymore @@ -178,9 +172,9 @@ return mapping; } finally { if (success) { - IOUtils.close(stream); + IOUtils.close(stream, input); } else { - IOUtils.closeWhileHandlingException(stream); + IOUtils.closeWhileHandlingException(stream, input); } } }