Index: src/java/org/apache/lucene/index/CheckIndex.java =================================================================== --- src/java/org/apache/lucene/index/CheckIndex.java (revision 965112) +++ src/java/org/apache/lucene/index/CheckIndex.java (working copy) @@ -347,8 +347,8 @@ sFormat = "FORMAT_DIAGNOSTICS [Lucene 2.9]"; else if (format == SegmentInfos.FORMAT_4_0) sFormat = "FORMAT_FLEX_POSTINGS [Lucene 4.0]"; - else if (format < SegmentInfos.CURRENT_FORMAT) { - sFormat = "int=" + format + " [newer version of Lucene than this tool]"; + else if (format < SegmentInfos.CURRENT_FORMAT || format > SegmentInfos.MINIMUM_FORMAT) { + sFormat = "int=" + format + " [newer version of Lucene than this tool, or pre-3.0 index]"; skip = true; } Index: src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosReader.java =================================================================== --- src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosReader.java (revision 965112) +++ src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosReader.java (working copy) @@ -41,7 +41,7 @@ int format = input.readInt(); // check that it is a format we can understand - if (format < SegmentInfos.CURRENT_FORMAT) + if (format < SegmentInfos.CURRENT_FORMAT || format > SegmentInfos.MINIMUM_FORMAT) throw new CorruptIndexException("Unknown (newer than us?) format version: " + format); infos.version = input.readLong(); // read version Index: src/java/org/apache/lucene/index/codecs/preflex/SegmentTermEnum.java =================================================================== --- src/java/org/apache/lucene/index/codecs/preflex/SegmentTermEnum.java (revision 965112) +++ src/java/org/apache/lucene/index/codecs/preflex/SegmentTermEnum.java (working copy) @@ -41,6 +41,9 @@ // NOTE: always change this if you switch to a new format! public static final int FORMAT_CURRENT = FORMAT_VERSION_UTF8_LENGTH_IN_BYTES; + + // when removing support for old versions, levae the last supported version here + public static final int FORMAT_MINIMUM = FORMAT_VERSION_UTF8_LENGTH_IN_BYTES; private TermBuffer termBuffer = new TermBuffer(); private TermBuffer prevBuffer = new TermBuffer(); @@ -78,8 +81,9 @@ format = firstInt; // check that it is a format we can understand - if (format < FORMAT_CURRENT) - throw new CorruptIndexException("Unknown format version:" + format + " expected " + FORMAT_CURRENT + " or higher"); + if (format > FORMAT_MINIMUM || format < FORMAT_CURRENT) + throw new CorruptIndexException("Incompatible format version: " + format + "; expected in range " + + FORMAT_MINIMUM + ".." + FORMAT_CURRENT); size = input.readLong(); // read the size Index: src/java/org/apache/lucene/index/FieldInfos.java =================================================================== --- src/java/org/apache/lucene/index/FieldInfos.java (revision 965112) +++ src/java/org/apache/lucene/index/FieldInfos.java (working copy) @@ -40,6 +40,7 @@ public static final int FORMAT_START = -2; static final int CURRENT_FORMAT = FORMAT_START; + static final int MINIMUM_FORMAT = FORMAT_START; static final byte IS_INDEXED = 0x1; static final byte STORE_TERMVECTOR = 0x2; @@ -307,7 +308,7 @@ private void read(IndexInput input, String fileName) throws IOException { format = input.readVInt(); - if (format > FORMAT_START) { + if (format < CURRENT_FORMAT || format > MINIMUM_FORMAT) { throw new CorruptIndexException("unrecognized format " + format + " in file \"" + fileName + "\""); } Index: src/java/org/apache/lucene/index/FieldsReader.java =================================================================== --- src/java/org/apache/lucene/index/FieldsReader.java (revision 965112) +++ src/java/org/apache/lucene/index/FieldsReader.java (working copy) @@ -104,9 +104,9 @@ format = cloneableIndexStream.readInt(); - if (format > FieldsWriter.FORMAT_CURRENT) - throw new CorruptIndexException("Incompatible format version: " + format + " expected " - + FieldsWriter.FORMAT_CURRENT + " or lower"); + if (format < FieldsWriter.FORMAT_MINIMUM || format > FieldsWriter.FORMAT_CURRENT) + throw new CorruptIndexException("Incompatible format version: " + format + "; expected in range " + + FieldsWriter.FORMAT_MINIMUM + ".." + FieldsWriter.FORMAT_CURRENT); fieldsStream = (IndexInput) cloneableFieldsStream.clone(); @@ -185,11 +185,9 @@ } boolean canReadRawDocs() { - // Disable reading raw docs in 2.x format, because of the removal of compressed - // fields in 3.0. We don't want rawDocs() to decode field bits to figure out - // if a field was compressed, hence we enforce ordinary (non-raw) stored field merges - // for <3.0 indexes. - return format >= FieldsWriter.FORMAT_LUCENE_3_0_NO_COMPRESSED_FIELDS; + // Since we currently only support >3.0 format anymore, always return true! + // I leave this method in because it may help for later format changes. + return true; } final Document doc(int n, FieldSelector fieldSelector) throws CorruptIndexException, IOException { @@ -306,7 +304,6 @@ private void addField(Document doc, FieldInfo fi, boolean binary, boolean tokenize) throws CorruptIndexException, IOException { - //we have a binary stored field, and it may be compressed if (binary) { int toRead = fieldsStream.readVInt(); final byte[] b = new byte[toRead]; Index: src/java/org/apache/lucene/index/FieldsWriter.java =================================================================== --- src/java/org/apache/lucene/index/FieldsWriter.java (revision 965112) +++ src/java/org/apache/lucene/index/FieldsWriter.java (working copy) @@ -39,6 +39,9 @@ // switch to a new format! static final int FORMAT_CURRENT = FORMAT_LUCENE_3_0_NO_COMPRESSED_FIELDS; + // when removing support for old versions, levae the last supported version here + static final int FORMAT_MINIMUM = FORMAT_LUCENE_3_0_NO_COMPRESSED_FIELDS; + private FieldInfos fieldInfos; private IndexOutput fieldsStream; Index: src/java/org/apache/lucene/index/SegmentInfos.java =================================================================== --- src/java/org/apache/lucene/index/SegmentInfos.java (revision 965112) +++ src/java/org/apache/lucene/index/SegmentInfos.java (working copy) @@ -67,6 +67,9 @@ /* This must always point to the most recent file format. */ public static final int CURRENT_FORMAT = FORMAT_4_0; + /* This must always point to the first supported file format. */ + public static final int MINIMUM_FORMAT = FORMAT_DIAGNOSTICS; + public int counter = 0; // used to name new segments /** Index: src/java/org/apache/lucene/index/TermVectorsReader.java =================================================================== --- src/java/org/apache/lucene/index/TermVectorsReader.java (revision 965112) +++ src/java/org/apache/lucene/index/TermVectorsReader.java (working copy) @@ -36,6 +36,9 @@ // NOTE: always change this if you switch to a new format! static final int FORMAT_CURRENT = FORMAT_UTF8_LENGTH_IN_BYTES; + + // when removing support for old versions, levae the last supported version here + static final int FORMAT_MINIMUM = FORMAT_UTF8_LENGTH_IN_BYTES; //The size in bytes that the FORMAT_VERSION will take up at the beginning of each file static final int FORMAT_SIZE = 4; @@ -186,10 +189,9 @@ private int checkValidFormat(IndexInput in) throws CorruptIndexException, IOException { int format = in.readInt(); - if (format > FORMAT_CURRENT) { - throw new CorruptIndexException("Incompatible format version: " + format + " expected " - + FORMAT_CURRENT + " or less"); - } + if (format < FORMAT_MINIMUM || format > FORMAT_CURRENT) + throw new CorruptIndexException("Incompatible format version: " + format + "; expected in range " + + FORMAT_MINIMUM + ".." + FORMAT_CURRENT); return format; }