Buggy code:
Terms terms = ( fields == null ) ? null : fields . terms ( field ) ; TermsEnum termsEnum = null ; SolrIndexSearcher . DocsEnumState deState = null ; BytesRef term = null ; if ( terms != null ) { termsEnum = terms . iterator ( null ) ; if ( startTermBytes != null ) { if ( ( termsEnum . seekCeil ( startTermBytes , true ) ) == ( SeekStatus . END ) ) { termsEnum = null ; } else { term = termsEnum . term ( ) ; } } else { term = termsEnum . next ( ) ; } } DocsEnum docsEnum = null ; CharsRef charsRef = new CharsRef ( 10 ) ; if ( ( docs . size ( ) ) >= mincount ) { while ( term != null ) { if ( ( startTermBytes != null ) && ( ! ( term . startsWith ( startTermBytes ) ) ) ) break ; int df = termsEnum . docFreq ( ) ; if ( ( df > 0 ) && ( df > min ) ) { int c ; if ( df >= minDfFilterCache ) { if ( deState == null ) { deState = new SolrIndexSearcher . DocsEnumState ( ) ; deState . fieldName = field ; deState . liveDocs = MultiFields . getLiveDocs ( r ) ; deState . termsEnum = termsEnum ; deState . docsEnum = docsEnum ; } c = searcher . numDocs ( docs , deState ) ; docsEnum = deState . docsEnum ; } else { docsEnum = termsEnum . docs ( null , docsEnum ) ; c = 0 ; if ( docsEnum instanceof MultiDocsEnum ) { MultiDocsEnum [ ] subs = ( ( MultiDocsEnum ) ( docsEnum ) ) . getSubs ( ) ; int numSubs = ( ( MultiDocsEnum ) ( docsEnum ) ) . getNumSubs ( ) ; for ( int subindex = 0 ; subindex < numSubs ; subindex ++ ) { MultiDocsEnum . EnumWithSlice sub = subs [ subindex ] ; if ( ( sub . docsEnum ) == null ) continue ; DocsEnum . BulkReadResult bulk = sub . docsEnum . getBulkResult ( ) ; int base = sub . slice . start ; for ( ; ; ) { int nDocs = sub . docsEnum . read ( ) ; if ( nDocs == 0 ) break ; int [ ] docArr = bulk . docs . ints ; int end = ( bulk . docs . offset ) + nDocs ; for ( int i = bulk . docs . offset ; i < end ; i ++ ) { if ( fastForRandomSet . exists ( ( ( docArr [ i ] ) + base ) ) ) c ++ ; } } } } else { DocsEnum . BulkReadResult bulk = docsEnum . getBulkResult ( ) ; for ( ; ; ) { int nDocs = docsEnum . read ( ) ; if ( nDocs == 0 ) break ; int [ ] docArr = bulk . docs . ints ; int end = ( bulk . docs . offset ) + nDocs ; for ( int i = bulk . docs . offset ; i < end ; i ++ ) { if ( fastForRandomSet . exists ( docArr [ i ] ) ) c ++ ; } } } } if ( sortByCount ) { if ( c > min ) { <START_BUG> BytesRef termCopy = new BytesRef ( term ) ; <END_BUG> queue . add ( new SimpleFacets . CountPair < BytesRef , Integer > ( termCopy , c ) ) ; if ( ( queue . size ( ) ) >= maxsize ) min = queue . last ( ) . val ; } } else { if ( ( c >= mincount ) && ( ( -- off ) < 0 ) ) { if ( ( -- lim ) < 0 ) break ; ft . indexedToReadable ( term , charsRef ) ; res . add ( charsRef . toString ( ) , c ) ; } } } term = termsEnum . next ( ) ; } } if ( sortByCount ) { for ( SimpleFacets . CountPair < BytesRef , Integer > p : queue ) { if ( ( -- off ) >= 0 ) continue ; if ( ( -- lim ) < 0 ) break ; ft . indexedToReadable ( p . key , charsRef ) ; res . add ( charsRef . toString ( ) , p . val ) ; } } if ( missing ) { res . add ( null , SimpleFacets . getFieldMissingCount ( searcher , docs , field ) ) ; } return res ; } @ Deprecated public NamedList < Object > getFacetDateCounts ( ) throws IOException , ParseException { } @ Deprecated public void getFacetDateCounts ( String dateFacet , NamedList < Object > resOuter ) throws IOException , ParseException { } public NamedList < Object > getFacetRangeCounts ( ) throws IOException , ParseException { } void getFacetRangeCounts ( String facetRange , NamedList < Object > resOuter ) throws IOException , ParseException { } private < T extends Comparable < T > > NamedList getFacetRangeCounts ( final SchemaField sf , final SimpleFacets . RangeEndpointCalculator < T > calc ) throws IOException { } protected int rangeCount ( SchemaField sf , String low , String high , boolean iLow , boolean iHigh ) throws IOException { } @ Deprecated protected int rangeCount ( SchemaField sf , Date low , Date high , boolean iLow , boolean iHigh ) throws IOException { } public static class CountPair < K extends Comparable < ? super K > , V extends Comparable < ? super V > > implements Comparable < SimpleFacets . CountPair < K , V > > { public CountPair ( K k , V v ) { } public K key ;

Fix:
BytesRef termCopy = BytesRef . deepCopyOf ( term ) ;