From 2ba48030f391efc963a9de8a13e6d2cf13e954d2 Mon Sep 17 00:00:00 2001 From: Mike McCandless Date: Wed, 2 Mar 2016 06:10:53 -0500 Subject: [PATCH] SegmentInfos now throws IndexFormatTooOld if index is before 6.0.0 --- .../org/apache/lucene/index/SegmentInfos.java | 28 ++++++------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java index 642b320cf37..d8fd0c92533 100644 --- a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java +++ b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java @@ -304,11 +304,12 @@ public final class SegmentInfos implements Cloneable, Iterable= VERSION_53) { - // TODO: in the future (7.0? sigh) we can use this to throw IndexFormatTooOldException ... or just rely on the - // minSegmentLuceneVersion check instead: infos.luceneVersion = Version.fromBits(input.readVInt(), input.readVInt(), input.readVInt()); + if (infos.luceneVersion.onOrAfter(Version.LUCENE_6_0_0) == false) { + throw new IndexFormatTooOldException(input, "this index is too old (version: " + infos.luceneVersion + ")"); + } } else { - // else compute the min version down below in the for loop + throw new IndexFormatTooOldException(input, "this index segments file is too old (segment infos format: " + format + ")"); } infos.version = input.readLong(); @@ -319,18 +320,10 @@ public final class SegmentInfos implements Cloneable, Iterable= VERSION_53) { - if (numSegments > 0) { - infos.minSegmentLuceneVersion = Version.fromBits(input.readVInt(), input.readVInt(), input.readVInt()); - if (infos.minSegmentLuceneVersion.onOrAfter(Version.LUCENE_5_0_0) == false) { - throw new IndexFormatTooOldException(input, "this index contains a too-old segment (version: " + infos.minSegmentLuceneVersion + ")"); - } - } else { - // else leave as null: no segments - } + if (numSegments > 0) { + infos.minSegmentLuceneVersion = Version.fromBits(input.readVInt(), input.readVInt(), input.readVInt()); } else { - // else we recompute it below as we visit segments; it can't be used for throwing IndexFormatTooOldExc, but consumers of - // SegmentInfos can maybe still use it for other reasons + // else leave as null: no segments } long totalDocs = 0; @@ -382,11 +375,8 @@ public final class SegmentInfos implements Cloneable, Iterable