@@ -394,7 +394,33 @@ private static void parseSegmentInfos(
394394 String segName = input .readString ();
395395 byte [] segmentID = new byte [StringHelper .ID_LENGTH ];
396396 input .readBytes (segmentID , 0 , segmentID .length );
397- Codec codec = readCodec (input );
397+ Codec codec = null ;
398+ try {
399+ codec = readCodec (input );
400+ } catch (IllegalArgumentException e ) {
401+ if (e .getMessage () != null && e .getMessage ().contains ("Could not load codec" )) {
402+ // maybe we tried loading an old default codec which isn't present in backward-codecs
403+ // anymore.
404+ // aka index is too old
405+ throw new IndexFormatTooOldException (
406+ input ,
407+ "Index has segments derived from Lucene version "
408+ + infos .indexCreatedVersionMajor
409+ + ".x and is not supported by Lucene "
410+ + Version .LATEST
411+ + ". This Lucene version only supports indexes with major version "
412+ + minSupportedMajorVersion
413+ + " or later (found: "
414+ + infos .indexCreatedVersionMajor
415+ + ", minimum supported: "
416+ + minSupportedMajorVersion
417+ + "). To resolve this issue re-index your data using Lucene "
418+ + minSupportedMajorVersion
419+ + ".x or later." );
420+ } else {
421+ throw e ;
422+ }
423+ }
398424 SegmentInfo info =
399425 codec .segmentInfoFormat ().read (directory , segName , segmentID , IOContext .READONCE );
400426 info .setCodec (codec );
0 commit comments