Buggy code:
public class DirectSpellChecker { public static final StringDistance INTERNAL_LEVENSHTEIN = new LuceneLevenshteinDistance ( ) ; private int maxEdits = LevenshteinAutomata . MAXIMUM_SUPPORTED_DISTANCE ; private int minPrefix = 1 ; private int maxInspections = 5 ; private float accuracy = SpellChecker . DEFAULT_ACCURACY ; private float thresholdFrequency = 0.0F ; private int minQueryLength = 4 ; private float maxQueryFrequency = 0.01F ; private boolean lowerCaseTerms = true ; private Comparator < SuggestWord > comparator = SuggestWordQueue . DEFAULT_COMPARATOR ; private StringDistance distance = DirectSpellChecker . INTERNAL_LEVENSHTEIN ; public int getMaxEdits ( ) { } public void setMaxEdits ( int maxEdits ) { } public int getMinPrefix ( ) { } public void setMinPrefix ( int minPrefix ) { } public int getMaxInspections ( ) { } public void setMaxInspections ( int maxInspections ) { } public float getAccuracy ( ) { } public void setAccuracy ( float accuracy ) { } public float getThresholdFrequency ( ) { } public void setThresholdFrequency ( float thresholdFrequency ) { } public int getMinQueryLength ( ) { } public void setMinQueryLength ( int minQueryLength ) { } public float getMaxQueryFrequency ( ) { } public void setMaxQueryFrequency ( float maxQueryFrequency ) { } public boolean getLowerCaseTerms ( ) { } public void setLowerCaseTerms ( boolean lowerCaseTerms ) { } public Comparator < SuggestWord > getComparator ( ) { } public void setComparator ( Comparator < SuggestWord > comparator ) { } public StringDistance getDistance ( ) { } public void setDistance ( StringDistance distance ) { } public SuggestWord [ ] suggestSimilar ( Term term , int numSug , IndexReader ir ) throws IOException { } public SuggestWord [ ] suggestSimilar ( Term term , int numSug , IndexReader ir , SuggestMode suggestMode ) throws IOException { } public SuggestWord [ ] suggestSimilar ( Term term , int numSug , IndexReader ir , SuggestMode suggestMode , float accuracy ) throws IOException { } private Collection < DirectSpellChecker . ScoreTerm > suggestSimilar ( Term term , int numSug , IndexReader ir , int docfreq , int editDistance , float accuracy , final CharsRef spare ) throws IOException { AttributeSource atts = new AttributeSource ( ) ; MaxNonCompetitiveBoostAttribute maxBoostAtt = atts . addAttribute ( MaxNonCompetitiveBoostAttribute . class ) ; Terms terms = MultiFields . getTerms ( ir , term . field ( ) ) ; if ( terms == null ) { return Collections . emptyList ( ) ; } FuzzyTermsEnum e = new FuzzyTermsEnum ( terms , atts , term , editDistance , Math . max ( minPrefix , ( editDistance - 1 ) ) ) ; final PriorityQueue < DirectSpellChecker . ScoreTerm > stQueue = new PriorityQueue < DirectSpellChecker . ScoreTerm > ( ) ; BytesRef queryTerm = new BytesRef ( term . text ( ) ) ; BytesRef candidateTerm ; DirectSpellChecker . ScoreTerm st = new DirectSpellChecker . ScoreTerm ( ) ; BoostAttribute boostAtt = e . attributes ( ) . addAttribute ( BoostAttribute . class ) ; while ( ( candidateTerm = e . next ( ) ) != null ) { final float boost = boostAtt . getBoost ( ) ; if ( ( ( stQueue . size ( ) ) >= numSug ) && ( boost <= ( stQueue . peek ( ) . boost ) ) ) continue ; if ( queryTerm . bytesEquals ( candidateTerm ) ) continue ; int df = e . docFreq ( ) ; if ( df <= docfreq ) continue ; final float score ; final String termAsString ; if ( ( distance ) == ( DirectSpellChecker . INTERNAL_LEVENSHTEIN ) ) { termAsString = null ; score = ( boost // ( e . getScaleFactor ( ) ) ) + ( e . getMinSimilarity ( ) ) ; } else { termAsString = candidateTerm . utf8ToChars ( spare ) . toString ( ) ; score = distance . getDistance ( term . text ( ) , termAsString ) ; } if ( score < accuracy ) continue ; <START_BUG> st . term = new BytesRef ( candidateTerm ) ; <END_BUG> st . boost = boost ; st . docfreq = df ; st . termAsString = termAsString ; st . score = score ; stQueue . offer ( st ) ; st = ( ( stQueue . size ( ) ) > numSug ) ? stQueue . poll ( ) : new DirectSpellChecker . ScoreTerm ( ) ; maxBoostAtt . setMaxNonCompetitiveBoost ( ( ( stQueue . size ( ) ) >= numSug ? stQueue . peek ( ) . boost : Float . NEGATIVE_INFINITY ) ) ; } return stQueue ; } private static class ScoreTerm implements Comparable < DirectSpellChecker . ScoreTerm > { public BytesRef term ; public float boost ; public int docfreq ; public String termAsString ; public float score ; public int compareTo ( DirectSpellChecker . ScoreTerm other ) { } @ Override public int hashCode ( ) { } @ Override public boolean equals ( Object obj ) { } } }

Fix:
st . term = BytesRef . deepCopyOf ( candidateTerm ) ;