Buggy code:
} private static String EXTENSION = "ram" ; @ Override public FieldsConsumer fieldsConsumer ( SegmentWriteState state ) throws IOException { } private static final class FSTDocsEnum extends DocsEnum { private final IndexOptions indexOptions ; private final boolean storePayloads ; private byte [ ] buffer = new byte [ 16 ] ; private final ByteArrayDataInput in = new ByteArrayDataInput ( buffer ) ; private Bits liveDocs ; private int docUpto ; private int docID = - 1 ; private int accum ; private int freq ; private int payloadLen ; private int numDocs ; public FSTDocsEnum ( IndexOptions indexOptions , boolean storePayloads ) { } public boolean canReuse ( IndexOptions indexOptions , boolean storePayloads ) { } public MemoryPostingsFormat . FSTDocsEnum reset ( BytesRef bufferIn , Bits liveDocs , int numDocs ) { } @ Override public int nextDoc ( ) { } @ Override public int docID ( ) { } @ Override public int advance ( int target ) { } @ Override public int freq ( ) { } } private static final class FSTDocsAndPositionsEnum extends DocsAndPositionsEnum { private final boolean storePayloads ; private byte [ ] buffer = new byte [ 16 ] ; private final ByteArrayDataInput in = new ByteArrayDataInput ( buffer ) ; private Bits liveDocs ; private int docUpto ; private int docID = - 1 ; private int accum ; private int freq ; private int numDocs ; private int posPending ; private int payloadLength ; final boolean storeOffsets ; int offsetLength ; int startOffset ; private int pos ; private final BytesRef payload = new BytesRef ( ) ; public FSTDocsAndPositionsEnum ( boolean storePayloads , boolean storeOffsets ) { } public boolean canReuse ( boolean storePayloads , boolean storeOffsets ) { } public MemoryPostingsFormat . FSTDocsAndPositionsEnum reset ( BytesRef bufferIn , Bits liveDocs , int numDocs ) { } @ Override public int nextDoc ( ) { } @ Override public int nextPosition ( ) { } @ Override public int startOffset ( ) { } @ Override public int endOffset ( ) { } @ Override public BytesRef getPayload ( ) { } @ Override public int docID ( ) { } @ Override public int advance ( int target ) { } @ Override public int freq ( ) { } } private static final class FSTTermsEnum extends TermsEnum { private final FieldInfo field ; private final BytesRefFSTEnum < BytesRef > fstEnum ; private final ByteArrayDataInput buffer = new ByteArrayDataInput ( ) ; private boolean didDecode ; private int docFreq ; private long totalTermFreq ; private BytesRefFSTEnum . InputOutput < BytesRef > current ; public FSTTermsEnum ( FieldInfo field , FST < BytesRef > fst ) { } private void decodeMetaData ( ) { } @ Override public boolean seekExact ( BytesRef text , boolean useCache ) throws IOException { } @ Override public SeekStatus seekCeil ( BytesRef text , boolean useCache ) throws IOException { } @ Override public DocsEnum docs ( Bits liveDocs , DocsEnum reuse , int flags ) { } @ Override public DocsAndPositionsEnum docsAndPositions ( Bits liveDocs , DocsAndPositionsEnum reuse , int flags ) { } @ Override public BytesRef term ( ) { } @ Override public BytesRef next ( ) throws IOException { } @ Override public int docFreq ( ) { } @ Override public long totalTermFreq ( ) { } @ Override public Comparator < BytesRef > getComparator ( ) { } @ Override public void seekExact ( long ord ) { } @ Override public long ord ( ) { } } private static final class TermsReader extends Terms { private final long sumTotalTermFreq ; private final long sumDocFreq ; private final int docCount ; private final int termCount ; private FST < BytesRef > fst ; private final ByteSequenceOutputs outputs = ByteSequenceOutputs . getSingleton ( ) ; private final FieldInfo field ; public TermsReader ( FieldInfos fieldInfos , IndexInput in , int termCount ) throws IOException { } @ Override public long getSumTotalTermFreq ( ) { } @ Override public long getSumDocFreq ( ) { } @ Override public int getDocCount ( ) { } @ Override public long size ( ) { } @ Override public TermsEnum iterator ( TermsEnum reuse ) { } @ Override public Comparator < BytesRef > getComparator ( ) { } @ Override public boolean hasOffsets ( ) { } @ Override public boolean hasPositions ( ) { } @ Override public boolean hasPayloads ( ) { } } @ Override public FieldsProducer fieldsProducer ( SegmentReadState state ) throws IOException { final String fileName = IndexFileNames . segmentFileName ( state . segmentInfo . name , state . segmentSuffix , MemoryPostingsFormat . EXTENSION ) ; <START_BUG> final IndexInput in = state . dir . openInput ( fileName , READONCE ) ; <END_BUG> final SortedMap < String , MemoryPostingsFormat . TermsReader > fields = new TreeMap < String , MemoryPostingsFormat . TermsReader > ( ) ; try { while ( true ) { final int termCount = in . readVInt ( ) ; if ( termCount == 0 ) { break ; } final MemoryPostingsFormat . TermsReader termsReader = new MemoryPostingsFormat . TermsReader ( state . fieldInfos , in , termCount ) ; fields . put ( termsReader . field . name , termsReader ) ; } } finally { in . close ( ) ; } return new FieldsProducer ( ) { @ Override public Iterator < String > iterator ( ) { return Collections . unmodifiableSet ( fields . keySet ( ) ) . iterator ( ) ; } @ Override public Terms terms ( String field ) { return fields . get ( field ) ; } @ Override public int size ( ) { return fields . size ( ) ; } @ Override public void close ( ) { for ( MemoryPostingsFormat . TermsReader termsReader : fields . values ( ) ) { termsReader . fst = null ; } } } ; } }

Fix:
final IndexInput in = state . directory . openInput ( fileName , READONCE ) ;