Buggy code:
public class TestAppendingCodec extends LuceneTestCase { private static class AppendingIndexOutputWrapper extends IndexOutput { IndexOutput wrapped ; public AppendingIndexOutputWrapper ( IndexOutput wrapped ) { } @ Override public void close ( ) throws IOException { } @ Override public void flush ( ) throws IOException { } @ Override public long getFilePointer ( ) { } @ Override public long length ( ) throws IOException { } @ Override public void seek ( long pos ) throws IOException { } @ Override public void writeByte ( byte b ) throws IOException { } @ Override public void writeBytes ( byte [ ] b , int offset , int length ) throws IOException { } } @ SuppressWarnings ( "serial" ) private static class AppendingRAMDirectory extends MockDirectoryWrapper { public AppendingRAMDirectory ( Random random , Directory delegate ) { } @ Override public IndexOutput createOutput ( String name , IOContext context ) throws IOException { } } private static final String text = "the<seq2seq4repair_space>quick<seq2seq4repair_space>brown<seq2seq4repair_space>fox<seq2seq4repair_space>jumped<seq2seq4repair_space>over<seq2seq4repair_space>the<seq2seq4repair_space>lazy<seq2seq4repair_space>dog" ; public void testCodec ( ) throws Exception { Directory dir = new TestAppendingCodec . AppendingRAMDirectory ( random ( ) , new RAMDirectory ( ) ) ; IndexWriterConfig cfg = new IndexWriterConfig ( Version . LUCENE_40 , new org . apache . lucene . analysis . MockAnalyzer ( random ( ) ) ) ; cfg . setCodec ( new AppendingCodec ( ) ) ; ( ( org . apache . lucene . index . TieredMergePolicy ) ( cfg . getMergePolicy ( ) ) ) . setUseCompoundFile ( false ) ; IndexWriter writer = new IndexWriter ( dir , cfg ) ; Document doc = new Document ( ) ; FieldType storedTextType = new FieldType ( TextField . TYPE_STORED ) ; storedTextType . setStoreTermVectors ( true ) ; storedTextType . setStoreTermVectorPositions ( true ) ; storedTextType . setStoreTermVectorOffsets ( true ) ; doc . add ( newField ( "f" , TestAppendingCodec . text , storedTextType ) ) ; writer . addDocument ( doc ) ; writer . commit ( ) ; writer . addDocument ( doc ) ; writer . forceMerge ( 1 ) ; writer . close ( ) ; IndexReader reader = DirectoryReader . open ( dir , 1 ) ; assertEquals ( 2 , reader . numDocs ( ) ) ; Document doc2 = reader . document ( 0 ) ; assertEquals ( TestAppendingCodec . text , doc2 . get ( "f" ) ) ; Fields fields = MultiFields . getFields ( reader ) ; Terms terms = fields . terms ( "f" ) ; assertNotNull ( terms ) ; TermsEnum te = terms . iterator ( null ) ; assertEquals ( FOUND , te . seekCeil ( new BytesRef ( "quick" ) ) ) ; assertEquals ( FOUND , te . seekCeil ( new BytesRef ( "brown" ) ) ) ; assertEquals ( FOUND , te . seekCeil ( new BytesRef ( "fox" ) ) ) ; assertEquals ( FOUND , te . seekCeil ( new BytesRef ( "jumped" ) ) ) ; assertEquals ( FOUND , te . seekCeil ( new BytesRef ( "over" ) ) ) ; assertEquals ( FOUND , te . seekCeil ( new BytesRef ( "lazy" ) ) ) ; assertEquals ( FOUND , te . seekCeil ( new BytesRef ( "dog" ) ) ) ; assertEquals ( FOUND , te . seekCeil ( new BytesRef ( "the" ) ) ) ; <START_BUG> DocsEnum de = te . docs ( null , null , true ) ; <END_BUG> assertTrue ( ( ( de . advance ( 0 ) ) != ( DocIdSetIterator . NO_MORE_DOCS ) ) ) ; assertEquals ( 2 , de . freq ( ) ) ; assertTrue ( ( ( de . advance ( 1 ) ) != ( DocIdSetIterator . NO_MORE_DOCS ) ) ) ; assertTrue ( ( ( de . advance ( 2 ) ) == ( DocIdSetIterator . NO_MORE_DOCS ) ) ) ; reader . close ( ) ; } public void testCompoundFile ( ) throws Exception { } }

Fix:
DocsEnum de = te . docs ( null , null ) ;