Buggy code:
public abstract class AnalysisRequestHandlerBase extends RequestHandlerBase { public static final Set < BytesRef > EMPTY_BYTES_SET = Collections . emptySet ( ) ; @ Override public void handleRequestBody ( SolrQueryRequest req , SolrQueryResponse rsp ) throws Exception { } protected abstract NamedList doAnalysis ( SolrQueryRequest req ) throws Exception { } protected NamedList < ? extends Object > analyzeValue ( String value , AnalysisRequestHandlerBase . AnalysisContext context ) { } protected Set < BytesRef > getQueryTokenSet ( String query , Analyzer analyzer ) { try { final Set < BytesRef > tokens = new HashSet < BytesRef > ( ) ; final TokenStream tokenStream = analyzer . tokenStream ( "" , new StringReader ( query ) ) ; final TermToBytesRefAttribute bytesAtt = tokenStream . getAttribute ( TermToBytesRefAttribute . class ) ; final BytesRef bytes = bytesAtt . getBytesRef ( ) ; tokenStream . reset ( ) ; while ( tokenStream . incrementToken ( ) ) { bytesAtt . fillBytesRef ( ) ; <START_BUG> tokens . add ( new BytesRef ( bytes ) ) ; <END_BUG> } tokenStream . end ( ) ; tokenStream . close ( ) ; return tokens ; } catch ( IOException ioe ) { throw new RuntimeException ( "Error<seq2seq4repair_space>occured<seq2seq4repair_space>while<seq2seq4repair_space>iterating<seq2seq4repair_space>over<seq2seq4repair_space>tokenstream" , ioe ) ; } } private List < AttributeSource > analyzeTokenStream ( TokenStream tokenStream ) { } static Map < String , String > ATTRIBUTE_MAPPING = Collections . unmodifiableMap ( new HashMap < String , String > ( ) { } ) ; private List < NamedList > convertTokensToNamedLists ( final List < AttributeSource > tokenList , AnalysisRequestHandlerBase . AnalysisContext context ) { } private String writeCharStream ( NamedList < Object > out , CharStream input ) { } protected static final class ListBasedTokenStream extends TokenStream { private final List < AttributeSource > tokens ; private Iterator < AttributeSource > tokenIterator ; ListBasedTokenStream ( List < AttributeSource > tokens ) { } @ Override public boolean incrementToken ( ) throws IOException { } @ Override public void reset ( ) throws IOException { } } public interface TokenTrackingAttribute extends Attribute { void freezeStage ( ) { } void setActPosition ( int pos ) { } int [ ] getPositions ( ) { } void reset ( int [ ] basePositions , int position ) { } } public static final class TokenTrackingAttributeImpl extends AttributeImpl implements AnalysisRequestHandlerBase . TokenTrackingAttribute { private int [ ] basePositions = new int [ 0 ] ; private int position = 0 ; private transient int [ ] cachedPositions = null ; public void freezeStage ( ) { } public void setActPosition ( int pos ) { } public int [ ] getPositions ( ) { } public void reset ( int [ ] basePositions , int position ) { } @ Override public void clear ( ) { } @ Override public void reflectWith ( AttributeReflector reflector ) { } @ Override public void copyTo ( AttributeImpl target ) { } } protected static class AnalysisContext { private final String fieldName ; private final FieldType fieldType ; private final Analyzer analyzer ; private final Set < BytesRef > termsToMatch ; public AnalysisContext ( FieldType fieldType , Analyzer analyzer , Set < BytesRef > termsToMatch ) { } public AnalysisContext ( String fieldName , FieldType fieldType , Analyzer analyzer ) { } public AnalysisContext ( String fieldName , FieldType fieldType , Analyzer analyzer , Set < BytesRef > termsToMatch ) { } public String getFieldName ( ) { } public FieldType getFieldType ( ) { } public Analyzer getAnalyzer ( ) { } public Set < BytesRef > getTermsToMatch ( ) { } } }

Fix:
tokens . add ( BytesRef . deepCopyOf ( bytes ) ) ;