Buggy code:
public class TestPayloads extends LuceneTestCase { public void testPayload ( ) throws Exception { } public void testPayloadFieldBit ( ) throws Exception { } public void testPayloadsEncoding ( ) throws Exception { } private void performTest ( Directory dir ) throws Exception { } static final Charset utf8 = Charset . forName ( "UTF-8" ) ; private void generateRandomData ( byte [ ] data ) { } private byte [ ] generateRandomData ( int n ) { } private Term [ ] generateTerms ( String fieldName , int n ) { } void assertByteArrayEquals ( byte [ ] b1 , byte [ ] b2 ) { } void assertByteArrayEquals ( byte [ ] b1 , byte [ ] b2 , int b2offset , int b2length ) { } private static class PayloadAnalyzer extends Analyzer { Map < String , TestPayloads . PayloadAnalyzer . PayloadData > fieldToData = new HashMap < String , TestPayloads . PayloadAnalyzer . PayloadData > ( ) ; public PayloadAnalyzer ( ) { } public PayloadAnalyzer ( String field , byte [ ] data , int offset , int length ) { } void setPayloadData ( String field , byte [ ] data , int offset , int length ) { } @ Override public TokenStreamComponents createComponents ( String fieldName , Reader reader ) { } private static class PayloadData { byte [ ] data ; int offset ; int length ; PayloadData ( byte [ ] data , int offset , int length ) { } } } private static class PayloadFilter extends TokenFilter { private byte [ ] data ; private int length ; private int offset ; private int startOffset ; PayloadAttribute payloadAtt ; CharTermAttribute termAttribute ; public PayloadFilter ( TokenStream in , byte [ ] data , int offset , int length ) { } @ Override public boolean incrementToken ( ) throws IOException { } @ Override public void reset ( ) throws IOException { } } public void testThreadSafety ( ) throws Exception { } private class PoolingPayloadTokenStream extends TokenStream { private byte [ ] payload ; private boolean first ; private TestPayloads . ByteArrayPool pool ; private String term ; CharTermAttribute termAtt ; PayloadAttribute payloadAtt ; PoolingPayloadTokenStream ( TestPayloads . ByteArrayPool pool ) { } @ Override public boolean incrementToken ( ) throws IOException { } @ Override public void close ( ) throws IOException { } } private static class ByteArrayPool { private List < byte [ ] > pool ; ByteArrayPool ( int capacity , int size ) { } synchronized byte [ ] get ( ) { } synchronized void release ( byte [ ] b ) { } synchronized int size ( ) { } } public void testAcrossFields ( ) throws Exception { } public void testMixupDocs ( ) throws Exception { Directory dir = newDirectory ( ) ; IndexWriterConfig iwc = newIndexWriterConfig ( TEST_VERSION_CURRENT , null ) ; iwc . setMergePolicy ( newLogMergePolicy ( ) ) ; RandomIndexWriter writer = new RandomIndexWriter ( random ( ) , dir , iwc ) ; Document doc = new Document ( ) ; Field field = new org . apache . lucene . document . TextField ( "field" , "" , Store . NO ) ; TokenStream ts = new MockTokenizer ( new StringReader ( "here<seq2seq4repair_space>we<seq2seq4repair_space>go" ) , MockTokenizer . WHITESPACE , true ) ; assertFalse ( ts . hasAttribute ( PayloadAttribute . class ) ) ; field . setTokenStream ( ts ) ; doc . add ( field ) ; writer . addDocument ( doc ) ; Token withPayload = new Token ( "withPayload" , 0 , 11 ) ; withPayload . setPayload ( new BytesRef ( "test" ) ) ; ts = new CannedTokenStream ( withPayload ) ; assertTrue ( ts . hasAttribute ( PayloadAttribute . class ) ) ; field . setTokenStream ( ts ) ; writer . addDocument ( doc ) ; ts = new MockTokenizer ( new StringReader ( "another" ) , MockTokenizer . WHITESPACE , true ) ; assertFalse ( ts . hasAttribute ( PayloadAttribute . class ) ) ; field . setTokenStream ( ts ) ; writer . addDocument ( doc ) ; DirectoryReader reader = writer . getReader ( ) ; <START_BUG> AtomicReader sr = reader . getSequentialSubReaders ( ) . get ( 0 ) ; <END_BUG> DocsAndPositionsEnum de = sr . termPositionsEnum ( null , "field" , new BytesRef ( "withPayload" ) ) ; de . nextDoc ( ) ; de . nextPosition ( ) ; assertEquals ( new BytesRef ( "test" ) , de . getPayload ( ) ) ; writer . close ( ) ; reader . close ( ) ; dir . close ( ) ; } public void testMixupMultiValued ( ) throws Exception { } }

Fix:
AtomicReader sr = SlowCompositeReaderWrapper . wrap ( reader ) ;