@@ -346,25 +346,12 @@ public static final SegmentInfos readCommit(
346346 input );
347347 }
348348
349- if (indexCreatedVersion < minSupportedMajorVersion ) {
350- throw new IndexFormatTooOldException (
351- input ,
352- "This index was initially created with Lucene "
353- + indexCreatedVersion
354- + ".x while the current version is "
355- + Version .LATEST
356- + " and Lucene only supports reading"
357- + (minSupportedMajorVersion == Version .MIN_SUPPORTED_MAJOR
358- ? " the current and previous major versions"
359- : " from version " + minSupportedMajorVersion + " upwards" ));
360- }
361-
362349 SegmentInfos infos = new SegmentInfos (indexCreatedVersion );
363350 infos .id = id ;
364351 infos .generation = generation ;
365352 infos .lastGeneration = generation ;
366353 infos .luceneVersion = luceneVersion ;
367- parseSegmentInfos (directory , input , infos , format );
354+ parseSegmentInfos (directory , input , infos , format , minSupportedMajorVersion );
368355 return infos ;
369356
370357 } catch (Throwable t ) {
@@ -380,7 +367,12 @@ public static final SegmentInfos readCommit(
380367 }
381368
382369 private static void parseSegmentInfos (
383- 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 {
384376 infos .version = CodecUtil .readBELong (input );
385377 // System.out.println("READ sis version=" + infos.version);
386378 infos .counter = input .readVLong ();
@@ -397,6 +389,7 @@ private static void parseSegmentInfos(
397389 }
398390
399391 long totalDocs = 0 ;
392+
400393 for (int seg = 0 ; seg < numSegments ; seg ++) {
401394 String segName = input .readString ();
402395 byte [] segmentID = new byte [StringHelper .ID_LENGTH ];
@@ -490,6 +483,30 @@ private static void parseSegmentInfos(
490483 + infos .indexCreatedVersionMajor ,
491484 input );
492485 }
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+ }
493510 }
494511
495512 infos .userData = input .readMapOfStrings ();
@@ -512,11 +529,13 @@ private static Codec readCodec(DataInput input) throws IOException {
512529 } catch (IllegalArgumentException e ) {
513530 // maybe it's an old default codec that moved
514531 if (name .startsWith ("Lucene" )) {
515- throw new IllegalArgumentException (
532+ throw new IndexFormatTooOldException (
533+ input ,
516534 "Could not load codec '"
517535 + name
518- + "'. Did you forget to add lucene-backward-codecs.jar?" ,
519- e );
536+ + "'. "
537+ + e .getMessage ()
538+ + ". Did you forget to add lucene-backward-codecs.jar?" );
520539 }
521540 throw e ;
522541 }
0 commit comments