From 1b075c0ee80b5c2e230a0e2d4ec1097dcac8c1b9 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sat, 4 Oct 2014 15:18:05 +0000 Subject: [PATCH] LUCENE-5969: improved exceptions for ancient codec git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene5969@1629404 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene49/Lucene49DocValuesProducer.java | 67 +++++++++---------- 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene49/Lucene49DocValuesProducer.java b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene49/Lucene49DocValuesProducer.java index ef60d58fd95..284ad17f87f 100644 --- a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene49/Lucene49DocValuesProducer.java +++ b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene49/Lucene49DocValuesProducer.java @@ -73,17 +73,16 @@ import org.apache.lucene.util.packed.MonotonicBlockPackedReader; */ @Deprecated class Lucene49DocValuesProducer extends DocValuesProducer implements Closeable { - private final Map numerics; - private final Map binaries; - private final Map sortedSets; - private final Map sortedNumerics; - private final Map ords; - private final Map ordIndexes; + private final Map numerics = new HashMap<>(); + private final Map binaries = new HashMap<>(); + private final Map sortedSets = new HashMap<>(); + private final Map sortedNumerics = new HashMap<>(); + private final Map ords = new HashMap<>(); + private final Map ordIndexes = new HashMap<>(); private final AtomicLong ramBytesUsed; private final IndexInput data; private final int numFields; private final int maxDoc; - private final int version; // memory-resident structures private final Map addressInstances = new HashMap<>(); @@ -94,17 +93,16 @@ class Lucene49DocValuesProducer extends DocValuesProducer implements Closeable { // clone for merge: when merging we don't do any instances.put()s Lucene49DocValuesProducer(Lucene49DocValuesProducer original) throws IOException { assert Thread.holdsLock(original); - numerics = original.numerics; - binaries = original.binaries; - sortedSets = original.sortedSets; - sortedNumerics = original.sortedNumerics; - ords = original.ords; - ordIndexes = original.ordIndexes; + numerics.putAll(original.numerics); + binaries.putAll(original.binaries); + sortedSets.putAll(original.sortedSets); + sortedNumerics.putAll(original.sortedNumerics); + ords.putAll(original.ords); + ordIndexes.putAll(original.ordIndexes); ramBytesUsed = new AtomicLong(original.ramBytesUsed()); data = original.data.clone(); numFields = original.numFields; maxDoc = original.maxDoc; - version = original.version; addressInstances.putAll(original.addressInstances); ordIndexInstances.putAll(original.ordIndexInstances); merging = true; @@ -113,36 +111,31 @@ class Lucene49DocValuesProducer extends DocValuesProducer implements Closeable { /** expert: instantiates a new reader */ Lucene49DocValuesProducer(SegmentReadState state, String dataCodec, String dataExtension, String metaCodec, String metaExtension) throws IOException { String metaName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, metaExtension); - // read in the entries from the metadata file. - ChecksumIndexInput in = state.directory.openChecksumInput(metaName, state.context); this.maxDoc = state.segmentInfo.getDocCount(); merging = false; - boolean success = false; - try { - version = CodecUtil.checkHeader(in, metaCodec, - Lucene49DocValuesFormat.VERSION_START, - Lucene49DocValuesFormat.VERSION_CURRENT); - numerics = new HashMap<>(); - ords = new HashMap<>(); - ordIndexes = new HashMap<>(); - binaries = new HashMap<>(); - sortedSets = new HashMap<>(); - sortedNumerics = new HashMap<>(); - numFields = readFields(in, state.fieldInfos); - - CodecUtil.checkFooter(in); - success = true; - } finally { - if (success) { - IOUtils.close(in); - } else { - IOUtils.closeWhileHandlingException(in); + + int version = -1; + int numFields = -1; + + // read in the entries from the metadata file. + try (ChecksumIndexInput in = state.directory.openChecksumInput(metaName, state.context)) { + Throwable priorE = null; + try { + version = CodecUtil.checkHeader(in, metaCodec, + Lucene49DocValuesFormat.VERSION_START, + Lucene49DocValuesFormat.VERSION_CURRENT); + numFields = readFields(in, state.fieldInfos); + } catch (Throwable exception) { + priorE = exception; + } finally { + CodecUtil.checkFooter(in, priorE); } } + this.numFields = numFields; String dataName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, dataExtension); this.data = state.directory.openInput(dataName, state.context); - success = false; + boolean success = false; try { final int version2 = CodecUtil.checkHeader(data, dataCodec, Lucene49DocValuesFormat.VERSION_START,