Buggy code:
static class RAMPostings extends FieldsProducer { final Map < String , RAMOnlyPostingsFormat . RAMField > fieldToTerms = new TreeMap < String , RAMOnlyPostingsFormat . RAMField > ( ) ; @ Override public Terms terms ( String field ) { } @ Override public int size ( ) { } @ Override public FieldsEnum iterator ( ) { } @ Override public void close ( ) { } } static class RAMField extends Terms { final String field ; final SortedMap < String , RAMOnlyPostingsFormat . RAMTerm > termToDocs = new TreeMap < String , RAMOnlyPostingsFormat . RAMTerm > ( ) ; long sumTotalTermFreq ; long sumDocFreq ; int docCount ; RAMField ( String field ) { } @ Override public long size ( ) { } @ Override public long getSumTotalTermFreq ( ) { } @ Override public long getSumDocFreq ( ) throws IOException { } @ Override public int getDocCount ( ) throws IOException { } @ Override public TermsEnum iterator ( TermsEnum reuse ) { } @ Override public Comparator < BytesRef > getComparator ( ) { } } static class RAMTerm { final String term ; long totalTermFreq ; final List < RAMOnlyPostingsFormat . RAMDoc > docs = new ArrayList < RAMOnlyPostingsFormat . RAMDoc > ( ) ; public RAMTerm ( String term ) { } } static class RAMDoc { final int docID ; final int [ ] positions ; byte [ ] [ ] payloads ; public RAMDoc ( int docID , int freq ) { } } private static class RAMFieldsConsumer extends FieldsConsumer { private final RAMOnlyPostingsFormat . RAMPostings postings ; private final RAMOnlyPostingsFormat . RAMTermsConsumer termsConsumer = new RAMOnlyPostingsFormat . RAMTermsConsumer ( ) ; public RAMFieldsConsumer ( RAMOnlyPostingsFormat . RAMPostings postings ) { } @ Override public TermsConsumer addField ( FieldInfo field ) { } @ Override public void close ( ) { } } private static class RAMTermsConsumer extends TermsConsumer { private RAMOnlyPostingsFormat . RAMField field ; private final RAMOnlyPostingsFormat . RAMPostingsWriterImpl postingsWriter = new RAMOnlyPostingsFormat . RAMPostingsWriterImpl ( ) ; RAMOnlyPostingsFormat . RAMTerm current ; void reset ( RAMOnlyPostingsFormat . RAMField field ) { } @ Override public PostingsConsumer startTerm ( BytesRef text ) { } @ Override public Comparator < BytesRef > getComparator ( ) { } @ Override public void finishTerm ( BytesRef text , TermStats stats ) { } @ Override public void finish ( long sumTotalTermFreq , long sumDocFreq , int docCount ) { } } static class RAMPostingsWriterImpl extends PostingsConsumer { private RAMOnlyPostingsFormat . RAMTerm term ; private RAMOnlyPostingsFormat . RAMDoc current ; private int posUpto = 0 ; public void reset ( RAMOnlyPostingsFormat . RAMTerm term ) { } @ Override public void startDoc ( int docID , int freq ) { } @ Override public void addPosition ( int position , BytesRef payload , int startOffset , int endOffset ) { } @ Override public void finishDoc ( ) { } } static class RAMFieldsEnum extends FieldsEnum { private final RAMOnlyPostingsFormat . RAMPostings postings ; private final Iterator < String > it ; private String current ; public RAMFieldsEnum ( RAMOnlyPostingsFormat . RAMPostings postings ) { } @ Override public String next ( ) { } @ Override public Terms terms ( ) { } } static class RAMTermsEnum extends TermsEnum { Iterator < String > it ; String current ; private final RAMOnlyPostingsFormat . RAMField ramField ; public RAMTermsEnum ( RAMOnlyPostingsFormat . RAMField field ) { } @ Override public Comparator < BytesRef > getComparator ( ) { } @ Override public BytesRef next ( ) { } @ Override public SeekStatus seekCeil ( BytesRef term , boolean useCache ) { } @ Override public void seekExact ( long ord ) { } @ Override public long ord ( ) { } @ Override public BytesRef term ( ) { } @ Override public int docFreq ( ) { } @ Override public long totalTermFreq ( ) { } @ Override <START_BUG> public DocsEnum docs ( Bits liveDocs , DocsEnum reuse , boolean needsFreqs ) { <END_BUG> return new RAMOnlyPostingsFormat . RAMDocsEnum ( ramField . termToDocs . get ( current ) , liveDocs ) ; } @ Override public DocsAndPositionsEnum docsAndPositions ( Bits liveDocs , DocsAndPositionsEnum reuse , int flags ) { } } private static class RAMDocsEnum extends DocsEnum { private final RAMOnlyPostingsFormat . RAMTerm ramTerm ; private final Bits liveDocs ; private RAMOnlyPostingsFormat . RAMDoc current ; int upto = - 1 ; int posUpto = 0 ; public RAMDocsEnum ( RAMOnlyPostingsFormat . RAMTerm ramTerm , Bits liveDocs ) { } @ Override public int advance ( int targetDocID ) { } @ Override public int nextDoc ( ) { } @ Override public int freq ( ) throws IOException { } @ Override public int docID ( ) { } } private static class RAMDocsAndPositionsEnum extends DocsAndPositionsEnum { private final RAMOnlyPostingsFormat . RAMTerm ramTerm ; private final Bits liveDocs ; private RAMOnlyPostingsFormat . RAMDoc current ; int upto = - 1 ; int posUpto = 0 ; public RAMDocsAndPositionsEnum ( RAMOnlyPostingsFormat . RAMTerm ramTerm , Bits liveDocs ) { } @ Override public int advance ( int targetDocID ) { } @ Override public int nextDoc ( ) { } @ Override public int freq ( ) throws IOException { } @ Override public int docID ( ) { } @ Override public int nextPosition ( ) { } @ Override public int startOffset ( ) { } @ Override public int endOffset ( ) { } @ Override public boolean hasPayload ( ) { } @ Override public BytesRef getPayload ( ) { } } private final Map < Integer , RAMOnlyPostingsFormat . RAMPostings > state = new HashMap < Integer , RAMOnlyPostingsFormat . RAMPostings > ( ) ; private final AtomicInteger nextID = new AtomicInteger ( ) ; private final String RAM_ONLY_NAME = "RAMOnly" ; private static final int VERSION_START = 0 ; private static final int VERSION_LATEST = RAMOnlyPostingsFormat . VERSION_START ;

Fix:
public DocsEnum docs ( Bits liveDocs , DocsEnum reuse , int flags ) {