You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2012/06/14 00:46:41 UTC
svn commit: r1350047 - in /lucene/dev/trunk/lucene/core/src:
java/org/apache/lucene/index/BaseCompositeReader.java
test/org/apache/lucene/index/Test2BDocs.java
Author: uschindler
Date: Wed Jun 13 22:46:41 2012
New Revision: 1350047
URL: http://svn.apache.org/viewvc?rev=1350047&view=rev
Log:
LUCENE-4137: BaseCompositeReader should throw exception if docids overflow
Added:
lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/Test2BDocs.java (with props)
Modified:
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/BaseCompositeReader.java
Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/BaseCompositeReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/BaseCompositeReader.java?rev=1350047&r1=1350046&r2=1350047&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/BaseCompositeReader.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/BaseCompositeReader.java Wed Jun 13 22:46:41 2012
@@ -70,6 +70,9 @@ public abstract class BaseCompositeReade
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;
Added: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/Test2BDocs.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/Test2BDocs.java?rev=1350047&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/Test2BDocs.java (added)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/Test2BDocs.java Wed Jun 13 22:46:41 2012
@@ -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();
+ }
+}