We just discovered this problem as well. Here's a test case that fails without the fix.
Index: src/test/org/apache/lucene/index/TestCompoundFile.java =================================================================== --- src/test/org/apache/lucene/index/TestCompoundFile.java (revision 382277) +++ src/test/org/apache/lucene/index/TestCompoundFile.java (working copy) @@ -622,4 +622,26 @@ is.close(); cr.close(); } + + /** This test that writes larger than the size of the buffer output + * will correctly increment the file pointer. + */ + public void testLargeWrites() throws IOException { + IndexOutput os = dir.createOutput("testBufferStart.txt"); + + byte[] largeBuf = new byte[2048]; + for (int i=0; i<largeBuf.length; i++) { + largeBuf[i] = (byte) (Math.random() * 256); + } + + long currentPos = os.getFilePointer(); + os.writeBytes(largeBuf, largeBuf.length); + + try { + assertEquals(currentPos + largeBuf.length, os.getFilePointer()); + } finally { + os.close(); + } + + } } Index: src/java/org/apache/lucene/store/BufferedIndexOutput.java =================================================================== --- src/java/org/apache/lucene/store/BufferedIndexOutput.java (revision 382277) +++ src/java/org/apache/lucene/store/BufferedIndexOutput.java (working copy) @@ -58,6 +58,7 @@ flush(); // and write data at once flushBuffer(b, length); + bufferStart += length; } else { // we fill/flush the buffer (until the input is written) int pos = 0; // position in the input data -----Original Message----- From: Doug Cutting [mailto:[EMAIL PROTECTED] Sent: Thursday, March 02, 2006 11:20 AM To: java-dev@lucene.apache.org Subject: Re: 1.9 RC1 Shay Banon wrote: > ... > } else { > // is data larger then buffer? > if (length > BUFFER_SIZE) { > // we flush the buffer > if (bufferPosition > 0) > flush(); > // and write data at once > flushBuffer(b, length); > } else { > ... > > the bufferStart is not incremented after the flushBuffer method is > called. So if someone calls getFilePointer just afterwards, it will > give the wrong result (hit it with the compound format). A simple fix > would be to add bufferStart += length; just after flushBuffer. Can you please file a bug for this and attach a bug to it with a unit test that illustrates the problem? This looks like something that could warrant a 1.9.1 release, so we must proceed carefully. Thanks, Doug --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]