[
https://issues.apache.org/jira/browse/LUCENE-7822?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16017097#comment-16017097
]
Adrien Grand commented on LUCENE-7822:
--------------------------------------
I'm not happy with swallowing the IAE entirely. What about doing something like
this:
{code}
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 e463259..677152c 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
+++ b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
@@ -289,11 +289,18 @@ public final class SegmentInfos implements Cloneable,
Iterable<SegmentCommitInfo
long generation = generationFromSegmentsFileName(segmentFileName);
//System.out.println(Thread.currentThread() + ": SegmentInfos.readCommit "
+ segmentFileName);
try (ChecksumIndexInput input =
directory.openChecksumInput(segmentFileName, IOContext.READ)) {
+ Throwable priorE = null;
+ SegmentInfos infos = null;
try {
- return readCommit(directory, input, generation);
+ infos = readCommit(directory, input, generation);
} catch (EOFException | NoSuchFileException | FileNotFoundException e) {
- throw new CorruptIndexException("Unexpected file read error while
reading index.", input, e);
+ priorE = new CorruptIndexException("Unexpected file read error while
reading index.", input, e);
+ } catch (Throwable t) {
+ priorE = t;
+ } finally {
+ CodecUtil.checkFooter(input, priorE);
}
+ return infos;
}
}
@@ -399,8 +406,6 @@ public final class SegmentInfos implements Cloneable,
Iterable<SegmentCommitInfo
infos.userData = input.readMapOfStrings();
- CodecUtil.checkFooter(input);
-
// LUCENE-6299: check we are in bounds
if (totalDocs > IndexWriter.getActualMaxDocs()) {
throw new CorruptIndexException("Too many documents: an index cannot
exceed " + IndexWriter.getActualMaxDocs() + " but readers have total maxDoc=" +
totalDocs, input);
{code}
This would add the CorruptIndexException as a suppressed exception to the IAE
so that it is clear this exception was caused by a corruption? It would also be
aligned with eg. how Lucene70SegmentInfoFormat (which also calls
Version.fromBits) handles unexpected exceptions.
> IllegalArgumentException thrown instead of a CorruptIndexException
> ------------------------------------------------------------------
>
> Key: LUCENE-7822
> URL: https://issues.apache.org/jira/browse/LUCENE-7822
> Project: Lucene - Core
> Issue Type: Bug
> Affects Versions: 6.5.1
> Reporter: Martin Amirault
> Priority: Minor
> Attachments: LUCENE-7822.patch
>
>
> Similarly to LUCENE-7592 , When an {{*.si}} file is corrupted on very
> specific part an IllegalArgumentException is thrown instead of a
> CorruptIndexException.
> StackTrace (Lucene 6.5.1):
> {code}
> java.lang.IllegalArgumentException: Illegal minor version: 12517381
> at
> __randomizedtesting.SeedInfo.seed([1FEB5987CFA44BE:B8755B5574F9F3BF]:0)
> at org.apache.lucene.util.Version.<init>(Version.java:385)
> at org.apache.lucene.util.Version.<init>(Version.java:371)
> at org.apache.lucene.util.Version.fromBits(Version.java:353)
> at
> org.apache.lucene.codecs.lucene62.Lucene62SegmentInfoFormat.read(Lucene62SegmentInfoFormat.java:97)
> at
> org.apache.lucene.index.SegmentInfos.readCommit(SegmentInfos.java:357)
> at
> org.apache.lucene.index.SegmentInfos.readCommit(SegmentInfos.java:288)
> at org.apache.lucene.index.SegmentInfos$1.doBody(SegmentInfos.java:448)
> at org.apache.lucene.index.SegmentInfos$1.doBody(SegmentInfos.java:445)
> at
> org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:692)
> at
> org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:644)
> at
> org.apache.lucene.index.SegmentInfos.readLatestCommit(SegmentInfos.java:450)
> at
> org.apache.lucene.index.DirectoryReader.listCommits(DirectoryReader.java:260)
> {code}
> Simple fix would be to add IllegalArgumentException to the catch list at
> {{org/apache/lucene/index/SegmentInfos.java:289}}
> Other variations for the stacktraces:
> {code}
> java.lang.IllegalArgumentException: invalid codec filename '_�.cfs', must
> match: _[a-z0-9]+(_.*)?\..*
> at
> __randomizedtesting.SeedInfo.seed([8B3FDE317B8D634A:A8EE07E5EB4B0B13]:0)
> at
> org.apache.lucene.index.SegmentInfo.checkFileNames(SegmentInfo.java:270)
> at org.apache.lucene.index.SegmentInfo.addFiles(SegmentInfo.java:252)
> at org.apache.lucene.index.SegmentInfo.setFiles(SegmentInfo.java:246)
> at
> org.apache.lucene.codecs.lucene62.Lucene62SegmentInfoFormat.read(Lucene62SegmentInfoFormat.java:248)
> at
> org.apache.lucene.index.SegmentInfos.readCommit(SegmentInfos.java:357)
> at
> org.apache.lucene.index.SegmentInfos.readCommit(SegmentInfos.java:288)
> at org.apache.lucene.index.SegmentInfos$1.doBody(SegmentInfos.java:448)
> at org.apache.lucene.index.SegmentInfos$1.doBody(SegmentInfos.java:445)
> at
> org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:692)
> at
> org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:644)
> at
> org.apache.lucene.index.SegmentInfos.readLatestCommit(SegmentInfos.java:450)
> at
> org.apache.lucene.index.DirectoryReader.listCommits(DirectoryReader.java:260)
> {code}
> {code}
> java.lang.IllegalArgumentException: An SPI class of type
> org.apache.lucene.codecs.Codec with name 'LucenI62' does not exist. You need
> to add the corresponding JAR file supporting this SPI to your classpath. The
> current classpath supports the following names: [Lucene62, Lucene50,
> Lucene53, Lucene54, Lucene60]
> at
> __randomizedtesting.SeedInfo.seed([925DE160F7260F99:B026EB9373CB6368]:0)
> at org.apache.lucene.util.NamedSPILoader.lookup(NamedSPILoader.java:116)
> at org.apache.lucene.codecs.Codec.forName(Codec.java:116)
> at org.apache.lucene.index.SegmentInfos.readCodec(SegmentInfos.java:424)
> at
> org.apache.lucene.index.SegmentInfos.readCommit(SegmentInfos.java:356)
> at
> org.apache.lucene.index.SegmentInfos.readCommit(SegmentInfos.java:288)
> at org.apache.lucene.index.SegmentInfos$1.doBody(SegmentInfos.java:448)
> at org.apache.lucene.index.SegmentInfos$1.doBody(SegmentInfos.java:445)
> at
> org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:692)
> at
> org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:644)
> at
> org.apache.lucene.index.SegmentInfos.readLatestCommit(SegmentInfos.java:450)
> at
> org.apache.lucene.index.DirectoryReader.listCommits(DirectoryReader.java:260)
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]