Buggy code:
public class Lucene40TermVectorsReader extends TermVectorsReader { static final byte STORE_POSITIONS_WITH_TERMVECTOR = 1 ; static final byte STORE_OFFSET_WITH_TERMVECTOR = 2 ; static final String VECTORS_FIELDS_EXTENSION = "tvf" ; static final String VECTORS_DOCUMENTS_EXTENSION = "tvd" ; static final String VECTORS_INDEX_EXTENSION = "tvx" ; static final String CODEC_NAME_FIELDS = "Lucene40TermVectorsFields" ; static final String CODEC_NAME_DOCS = "Lucene40TermVectorsDocs" ; static final String CODEC_NAME_INDEX = "Lucene40TermVectorsIndex" ; static final int VERSION_START = 0 ; static final int VERSION_CURRENT = Lucene40TermVectorsReader . VERSION_START ; static final long HEADER_LENGTH_FIELDS = CodecUtil . headerLength ( Lucene40TermVectorsReader . CODEC_NAME_FIELDS ) ; static final long HEADER_LENGTH_DOCS = CodecUtil . headerLength ( Lucene40TermVectorsReader . CODEC_NAME_DOCS ) ; static final long HEADER_LENGTH_INDEX = CodecUtil . headerLength ( Lucene40TermVectorsReader . CODEC_NAME_INDEX ) ; private FieldInfos fieldInfos ; private IndexInput tvx ; private IndexInput tvd ; private IndexInput tvf ; private int size ; private int numTotalDocs ; Lucene40TermVectorsReader ( FieldInfos fieldInfos , IndexInput tvx , IndexInput tvd , IndexInput tvf , int size , int numTotalDocs ) { } public Lucene40TermVectorsReader ( Directory d , SegmentInfo si , FieldInfos fieldInfos , IOContext context ) throws IOException { } IndexInput getTvdStream ( ) { } IndexInput getTvfStream ( ) { } void seekTvx ( final int docNum ) throws IOException { } final void rawDocs ( int [ ] tvdLengths , int [ ] tvfLengths , int startDocID , int numDocs ) throws IOException { } public void close ( ) throws IOException { } int size ( ) { } private class TVFields extends Fields { private final int [ ] fieldNumbers ; private final long [ ] fieldFPs ; private final Map < Integer , Integer > fieldNumberToIndex = new HashMap < Integer , Integer > ( ) ; public TVFields ( int docID ) throws IOException { } @ Override public FieldsEnum iterator ( ) throws IOException { } @ Override public Terms terms ( String field ) throws IOException { } @ Override public int size ( ) { } } private class TVTerms extends Terms { private final int numTerms ; private final long tvfFPStart ; public TVTerms ( long tvfFP ) throws IOException { } @ Override public TermsEnum iterator ( TermsEnum reuse ) throws IOException { } @ Override public long size ( ) { } @ Override public long getSumTotalTermFreq ( ) { } @ Override public long getSumDocFreq ( ) { } @ Override public int getDocCount ( ) { } @ Override public Comparator < BytesRef > getComparator ( ) { } } private class TVTermsEnum extends TermsEnum { private final IndexInput origTVF ; private final IndexInput tvf ; private int numTerms ; private int nextTerm ; private int freq ; private BytesRef lastTerm = new BytesRef ( ) ; private BytesRef term = new BytesRef ( ) ; private boolean storePositions ; private boolean storeOffsets ; private long tvfFP ; private int [ ] positions ; private int [ ] startOffsets ; private int [ ] endOffsets ; public TVTermsEnum ( ) { } public boolean canReuse ( IndexInput tvf ) { } public void reset ( int numTerms , long tvfFPStart ) throws IOException { } @ Override public SeekStatus seekCeil ( BytesRef text , boolean useCache ) throws IOException { } @ Override public void seekExact ( long ord ) { } @ Override public BytesRef next ( ) throws IOException { } @ Override public BytesRef term ( ) { } @ Override public long ord ( ) { } @ Override public int docFreq ( ) { } @ Override public long totalTermFreq ( ) { } @ Override <START_BUG> public DocsEnum docs ( Bits liveDocs , DocsEnum reuse , int flags ) throws IOException { <END_BUG> Lucene40TermVectorsReader . TVDocsEnum docsEnum ; if ( ( reuse != null ) && ( reuse instanceof Lucene40TermVectorsReader . TVDocsEnum ) ) { docsEnum = ( ( Lucene40TermVectorsReader . TVDocsEnum ) ( reuse ) ) ; } else { docsEnum = new Lucene40TermVectorsReader . TVDocsEnum ( ) ; } docsEnum . reset ( liveDocs , freq ) ; return docsEnum ; } @ Override public DocsAndPositionsEnum docsAndPositions ( Bits liveDocs , DocsAndPositionsEnum reuse , int flags ) throws IOException { } @ Override public Comparator < BytesRef > getComparator ( ) { } } private static class TVDocsEnum extends DocsEnum { private boolean didNext ; private int doc = - 1 ; private int freq ; private Bits liveDocs ; @ Override public int freq ( ) throws IOException { } @ Override public int docID ( ) { } @ Override public int nextDoc ( ) { } @ Override public int advance ( int target ) { } public void reset ( Bits liveDocs , int freq ) { } } private static class TVDocsAndPositionsEnum extends DocsAndPositionsEnum { private boolean didNext ; private int doc = - 1 ; private int nextPos ; private Bits liveDocs ; private int [ ] positions ; private int [ ] startOffsets ; private int [ ] endOffsets ; @ Override public int freq ( ) throws IOException { } @ Override public int docID ( ) { } @ Override public int nextDoc ( ) { } @ Override public int advance ( int target ) { } public void reset ( Bits liveDocs , int [ ] positions , int [ ] startOffsets , int [ ] endOffsets ) { } @ Override public BytesRef getPayload ( ) { } @ Override public boolean hasPayload ( ) { } @ Override public int nextPosition ( ) { } @ Override public int startOffset ( ) { } @ Override public int endOffset ( ) { } } @ Override public Fields get ( int docID ) throws IOException { } @ Override public TermVectorsReader clone ( ) { } }

Fix:
public DocsEnum docs ( Bits liveDocs , DocsEnum reuse , boolean needsFreqs ) throws IOException {