From 3813f5ab7c78b81d4bcfc78788e44609c6f8d636 Mon Sep 17 00:00:00 2001 From: Kartik Ganesh Date: Tue, 18 Apr 2023 11:38:35 -0700 Subject: [PATCH] Change the access modifier for the "expert" readLatestCommit API to public. (#12229) This change also includes a unit test for this functionality. Signed-off-by: Kartik Ganesh --- .../backward_index/TestBackwardsCompatibility.java | 14 ++++++++++++++ .../java/org/apache/lucene/index/SegmentInfos.java | 10 ++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_index/TestBackwardsCompatibility.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_index/TestBackwardsCompatibility.java index a2790d873c6..9eeebeefc62 100644 --- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_index/TestBackwardsCompatibility.java +++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_index/TestBackwardsCompatibility.java @@ -2241,4 +2241,18 @@ public class TestBackwardsCompatibility extends LuceneTestCase { } } } + + @Nightly + public void testReadNMinusTwoSegmentInfos() throws IOException { + for (String name : binarySupportedNames) { + Path oldIndexDir = createTempDir(name); + TestUtil.unzip(getDataInputStream("unsupported." + name + ".zip"), oldIndexDir); + try (BaseDirectoryWrapper dir = newFSDirectory(oldIndexDir)) { + expectThrows( + IndexFormatTooOldException.class, + () -> SegmentInfos.readLatestCommit(dir, Version.MIN_SUPPORTED_MAJOR)); + SegmentInfos.readLatestCommit(dir, MIN_BINARY_SUPPORTED_MAJOR); + } + } + } } 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 ecd064ac875..d2cb1abaa8a 100644 --- a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java +++ b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java @@ -517,8 +517,14 @@ public final class SegmentInfos implements Cloneable, Iterable(directory) { @Override protected SegmentInfos doBody(String segmentFileName) throws IOException {