mirror of https://github.com/apache/lucene.git
LUCENE-4137: BaseCompositeReader should throw exception if docids overflow
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1350047 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ee0d911d77
commit
ff9268e067
|
@ -70,6 +70,9 @@ public abstract class BaseCompositeReader<R extends IndexReader> extends Composi
|
|||
starts[i] = maxDoc;
|
||||
final IndexReader r = subReaders[i];
|
||||
maxDoc += r.maxDoc(); // compute maxDocs
|
||||
if (maxDoc < 0 /* overflow */) {
|
||||
throw new IllegalArgumentException("Too many documents, composite IndexReaders cannot exceed " + Integer.MAX_VALUE);
|
||||
}
|
||||
numDocs += r.numDocs(); // compute numDocs
|
||||
if (r.hasDeletions()) {
|
||||
hasDeletions = true;
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
package org.apache.lucene.index;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.lucene.util._TestUtil;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class Test2BDocs extends LuceneTestCase {
|
||||
static Directory dir;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
dir = newFSDirectory(_TestUtil.getTempDir("2Bdocs"));
|
||||
IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, null));
|
||||
Document doc = new Document();
|
||||
for (int i = 0; i < 262144; i++) {
|
||||
iw.addDocument(doc);
|
||||
}
|
||||
iw.forceMerge(1);
|
||||
iw.close();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
dir.close();
|
||||
dir = null;
|
||||
}
|
||||
|
||||
public void testOverflow() throws Exception {
|
||||
DirectoryReader ir = DirectoryReader.open(dir);
|
||||
IndexReader subReaders[] = new IndexReader[8192];
|
||||
Arrays.fill(subReaders, ir);
|
||||
try {
|
||||
new MultiReader(subReaders);
|
||||
fail();
|
||||
} catch (IllegalArgumentException expected) {
|
||||
// expected
|
||||
}
|
||||
ir.close();
|
||||
}
|
||||
|
||||
public void testExactlyAtLimit() throws Exception {
|
||||
Directory dir2 = newFSDirectory(_TestUtil.getTempDir("2BDocs2"));
|
||||
IndexWriter iw = new IndexWriter(dir2, new IndexWriterConfig(TEST_VERSION_CURRENT, null));
|
||||
Document doc = new Document();
|
||||
for (int i = 0; i < 262143; i++) {
|
||||
iw.addDocument(doc);
|
||||
}
|
||||
iw.close();
|
||||
DirectoryReader ir = DirectoryReader.open(dir);
|
||||
DirectoryReader ir2 = DirectoryReader.open(dir2);
|
||||
IndexReader subReaders[] = new IndexReader[8192];
|
||||
Arrays.fill(subReaders, ir);
|
||||
subReaders[subReaders.length-1] = ir2;
|
||||
MultiReader mr = new MultiReader(subReaders);
|
||||
assertEquals(Integer.MAX_VALUE, mr.maxDoc());
|
||||
assertEquals(Integer.MAX_VALUE, mr.numDocs());
|
||||
ir.close();
|
||||
ir2.close();
|
||||
dir2.close();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue