@@ -328,7 +328,7 @@ public static final SegmentInfos readCommit(
328328 throw new IndexFormatTooOldException (
329329 input , magic , CodecUtil .CODEC_MAGIC , CodecUtil .CODEC_MAGIC );
330330 }
331- format = CodecUtil .checkHeaderNoMagic (input , "segments" , VERSION_74 , VERSION_CURRENT );
331+ format = CodecUtil .checkHeaderNoMagic (input , "segments" , VERSION_86 , VERSION_CURRENT );
332332 byte [] id = new byte [StringHelper .ID_LENGTH ];
333333 input .readBytes (id , 0 , id .length );
334334 CodecUtil .checkIndexHeaderSuffix (input , Long .toString (generation , Character .MAX_RADIX ));
@@ -346,30 +346,12 @@ public static final SegmentInfos readCommit(
346346 input );
347347 }
348348
349- if (indexCreatedVersion < minSupportedMajorVersion ) {
350- throw new IndexFormatTooOldException (
351- input ,
352- "Index created with Lucene "
353- + indexCreatedVersion
354- + ".x is not supported by Lucene "
355- + Version .LATEST
356- + ". This Lucene version only supports indexes created with major version "
357- + minSupportedMajorVersion
358- + " or later (found: "
359- + indexCreatedVersion
360- + ", minimum: "
361- + minSupportedMajorVersion
362- + "). To resolve this issue: (1) Re-index your data using Lucene "
363- + Version .LATEST .major
364- + ".x, or (2) Use an older Lucene version that supports your index format." );
365- }
366-
367349 SegmentInfos infos = new SegmentInfos (indexCreatedVersion );
368350 infos .id = id ;
369351 infos .generation = generation ;
370352 infos .lastGeneration = generation ;
371353 infos .luceneVersion = luceneVersion ;
372- parseSegmentInfos (directory , input , infos , format );
354+ parseSegmentInfos (directory , input , infos , format , minSupportedMajorVersion );
373355 return infos ;
374356
375357 } catch (Throwable t ) {
@@ -385,7 +367,12 @@ public static final SegmentInfos readCommit(
385367 }
386368
387369 private static void parseSegmentInfos (
388- Directory directory , DataInput input , SegmentInfos infos , int format ) throws IOException {
370+ Directory directory ,
371+ DataInput input ,
372+ SegmentInfos infos ,
373+ int format ,
374+ int minSupportedMajorVersion )
375+ throws IOException {
389376 infos .version = CodecUtil .readBELong (input );
390377 // System.out.println("READ sis version=" + infos.version);
391378 infos .counter = input .readVLong ();
@@ -402,6 +389,7 @@ private static void parseSegmentInfos(
402389 }
403390
404391 long totalDocs = 0 ;
392+
405393 for (int seg = 0 ; seg < numSegments ; seg ++) {
406394 String segName = input .readString ();
407395 byte [] segmentID = new byte [StringHelper .ID_LENGTH ];
@@ -495,6 +483,30 @@ private static void parseSegmentInfos(
495483 + infos .indexCreatedVersionMajor ,
496484 input );
497485 }
486+
487+ int createdOrSegmentMinVersion =
488+ info .getMinVersion () == null
489+ ? infos .indexCreatedVersionMajor
490+ : info .getMinVersion ().major ;
491+
492+ // version >=7 are expected to record minVersion
493+ if (info .getMinVersion () == null || info .getMinVersion ().major < minSupportedMajorVersion ) {
494+ throw new IndexFormatTooOldException (
495+ input ,
496+ "Index has segments derived from Lucene version "
497+ + createdOrSegmentMinVersion
498+ + ".x and is not supported by Lucene "
499+ + Version .LATEST
500+ + ". This Lucene version only supports indexes with major version "
501+ + minSupportedMajorVersion
502+ + " or later (found: "
503+ + createdOrSegmentMinVersion
504+ + ", minimum supported: "
505+ + minSupportedMajorVersion
506+ + "). To resolve this issue re-index your data using Lucene "
507+ + minSupportedMajorVersion
508+ + ".x or later." );
509+ }
498510 }
499511
500512 infos .userData = input .readMapOfStrings ();
0 commit comments