mirror of https://github.com/apache/lucene.git
don't throw scary EOFE if you pass oob docID to IR.document
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1164620 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d535c65c95
commit
46fe671e8c
|
@ -974,6 +974,9 @@ public abstract class IndexReader implements Cloneable,Closeable {
|
||||||
// IndexableField
|
// IndexableField
|
||||||
public Document document(int docID) throws CorruptIndexException, IOException {
|
public Document document(int docID) throws CorruptIndexException, IOException {
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
|
if (docID < 0 || docID >= maxDoc()) {
|
||||||
|
throw new IllegalArgumentException("docID must be >= 0 and < maxDoc=" + maxDoc() + " (got docID=" + docID + ")");
|
||||||
|
}
|
||||||
final DocumentStoredFieldVisitor visitor = new DocumentStoredFieldVisitor();
|
final DocumentStoredFieldVisitor visitor = new DocumentStoredFieldVisitor();
|
||||||
document(docID, visitor);
|
document(docID, visitor);
|
||||||
return visitor.getDocument();
|
return visitor.getDocument();
|
||||||
|
|
|
@ -455,6 +455,9 @@ public class SegmentReader extends IndexReader implements Cloneable {
|
||||||
|
|
||||||
public void document(int docID, StoredFieldVisitor visitor) throws CorruptIndexException, IOException {
|
public void document(int docID, StoredFieldVisitor visitor) throws CorruptIndexException, IOException {
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
|
if (docID < 0 || docID >= maxDoc()) {
|
||||||
|
throw new IllegalArgumentException("docID must be >= 0 and < maxDoc=" + maxDoc() + " (got docID=" + docID + ")");
|
||||||
|
}
|
||||||
getFieldsReader().visitDocument(docID, visitor);
|
getFieldsReader().visitDocument(docID, visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1388,4 +1388,21 @@ public class TestIndexReader extends LuceneTestCase
|
||||||
assertEquals(3, closeCount[0]);
|
assertEquals(3, closeCount[0]);
|
||||||
dir.close();
|
dir.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testOOBDocID() throws Exception {
|
||||||
|
Directory dir = newDirectory();
|
||||||
|
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)));
|
||||||
|
writer.addDocument(new Document());
|
||||||
|
IndexReader r = writer.getReader();
|
||||||
|
writer.close();
|
||||||
|
r.document(0);
|
||||||
|
try {
|
||||||
|
r.document(1);
|
||||||
|
fail("did not hit exception");
|
||||||
|
} catch (IllegalArgumentException iae) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
r.close();
|
||||||
|
dir.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue