Index: src/test/org/apache/lucene/index/TestDocValuesIndexing.java =================================================================== --- src/test/org/apache/lucene/index/TestDocValuesIndexing.java (revision 1480054) +++ src/test/org/apache/lucene/index/TestDocValuesIndexing.java (working copy) @@ -328,27 +328,27 @@ } public void testTooLargeBytes() throws IOException { - Analyzer analyzer = new MockAnalyzer(random()); - - Directory directory = newDirectory(); - // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!1 - IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer); - iwc.setMergePolicy(newLogMergePolicy()); - IndexWriter iwriter = new IndexWriter(directory, iwc); + Directory d = newDirectory(); + IndexWriter w = new IndexWriter(d, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()))); Document doc = new Document(); - byte bytes[] = new byte[100000]; - BytesRef b = new BytesRef(bytes); + byte[] bytes = new byte[33000]; + BytesRef b = new BytesRef(); + b.bytes = bytes; + b.length = bytes.length; random().nextBytes(bytes); - doc.add(new BinaryDocValuesField("dv", b)); - try { - iwriter.addDocument(doc); - fail("did not get expected exception"); - } catch (IllegalArgumentException expected) { - // expected - } - iwriter.close(); + doc.add(new BinaryDocValuesField("field", b)); + w.addDocument(doc); + DirectoryReader r = w.getReader(); + BinaryDocValues s = FieldCache.DEFAULT.getTerms(getOnlySegmentReader(r), "field"); - directory.close(); + BytesRef bytes1 = new BytesRef(); + s.get(0, bytes1); + assertEquals(bytes.length, bytes1.length); + assertEquals(b, bytes1); + + r.close(); + w.close(); + d.close(); } public void testTooLargeSortedBytes() throws IOException { Index: src/java/org/apache/lucene/index/BinaryDocValuesWriter.java =================================================================== --- src/java/org/apache/lucene/index/BinaryDocValuesWriter.java (revision 1480054) +++ src/java/org/apache/lucene/index/BinaryDocValuesWriter.java (working copy) @@ -53,9 +53,6 @@ if (value == null) { throw new IllegalArgumentException("field=\"" + fieldInfo.name + "\": null value not allowed"); } - if (value.length > (BYTE_BLOCK_SIZE - 2)) { - throw new IllegalArgumentException("DocValuesField \"" + fieldInfo.name + "\" is too large, must be <= " + (BYTE_BLOCK_SIZE - 2)); - } // Fill in any holes: while(addedValues < docID) { Index: src/java/org/apache/lucene/util/ByteBlockPool.java =================================================================== --- src/java/org/apache/lucene/util/ByteBlockPool.java (revision 1480054) +++ src/java/org/apache/lucene/util/ByteBlockPool.java (working copy) @@ -345,7 +345,7 @@ System.arraycopy(buffer, pos, bytes, bytesOffset, bytesLength); break; } else { - final int bytesToCopy = length - overflow; + final int bytesToCopy = Math.min(length - overflow, BYTE_BLOCK_SIZE); System.arraycopy(buffer, pos, bytes, bytesOffset, bytesToCopy); pos = 0; bytesLength -= bytesToCopy;