Buggy code:
public final class TreeClusteringRecommender2 extends AbstractRecommender implements ClusteringRecommender { private static final Logger log = LoggerFactory . getLogger ( TreeClusteringRecommender2 . class ) ; private static final int NUM_CLUSTER_RECS = 100 ; private final ClusterSimilarity clusterSimilarity ; private final int numClusters ; private final double clusteringThreshold ; private final boolean clusteringByThreshold ; private FastByIDMap < List < RecommendedItem > > topRecsByUserID ; private FastIDSet [ ] allClusters ; private FastByIDMap < FastIDSet > clustersByUserID ; private final RefreshHelper refreshHelper ; public TreeClusteringRecommender2 ( DataModel dataModel , ClusterSimilarity clusterSimilarity , int numClusters ) throws TasteException { } public TreeClusteringRecommender2 ( DataModel dataModel , ClusterSimilarity clusterSimilarity , double clusteringThreshold ) throws TasteException { } @ Override public List < RecommendedItem > recommend ( long userID , int howMany , IDRescorer rescorer ) throws TasteException { } @ Override public float estimatePreference ( long userID , long itemID ) throws TasteException { } @ Override public FastIDSet getCluster ( long userID ) throws TasteException { } @ Override public FastIDSet [ ] getClusters ( ) throws TasteException { } private static final class ClusterClusterPair implements Comparable < TreeClusteringRecommender2 . ClusterClusterPair > { private final FastIDSet cluster1 ; private final FastIDSet cluster2 ; private final double similarity ; private ClusterClusterPair ( FastIDSet cluster1 , FastIDSet cluster2 , double similarity ) { } FastIDSet getCluster1 ( ) { } FastIDSet getCluster2 ( ) { } double getSimilarity ( ) { } @ Override public int hashCode ( ) { } @ Override public boolean equals ( Object o ) { } @ Override public int compareTo ( TreeClusteringRecommender2 . ClusterClusterPair other ) { } } private void buildClusters ( ) throws TasteException { } private boolean mergeClosestClusters ( int numUsers , List < FastIDSet > clusters , boolean done ) throws TasteException { List < TreeClusteringRecommender2 . ClusterClusterPair > queue = findClosestClusters ( numUsers , clusters ) ; while ( ! ( queue . isEmpty ( ) ) ) { if ( ( ! ( clusteringByThreshold ) ) && ( ( clusters . size ( ) ) <= ( numClusters ) ) ) { done = true ; break ; } TreeClusteringRecommender2 . ClusterClusterPair top = queue . remove ( 0 ) ; if ( ( clusteringByThreshold ) && ( ( top . getSimilarity ( ) ) < ( clusteringThreshold ) ) ) { done = true ; break ; } FastIDSet cluster1 = top . getCluster1 ( ) ; FastIDSet cluster2 = top . getCluster2 ( ) ; Iterator < FastIDSet > clusterIterator = clusters . iterator ( ) ; boolean removed1 = false ; boolean removed2 = false ; while ( ( clusterIterator . hasNext ( ) ) && ( ! ( removed1 && removed2 ) ) ) { FastIDSet current = clusterIterator . next ( ) ; if ( ( ! removed1 ) && ( cluster1 == current ) ) { clusterIterator . remove ( ) ; removed1 = true ; } else if ( ( ! removed2 ) && ( cluster2 == current ) ) { clusterIterator . remove ( ) ; removed2 = true ; } } for ( Iterator < TreeClusteringRecommender2 . ClusterClusterPair > queueIterator = queue . iterator ( ) ; queueIterator . hasNext ( ) ; ) { TreeClusteringRecommender2 . ClusterClusterPair pair = queueIterator . next ( ) ; FastIDSet pair1 = pair . getCluster1 ( ) ; FastIDSet pair2 = pair . getCluster2 ( ) ; if ( ( ( ( pair1 == cluster1 ) || ( pair1 == cluster2 ) ) || ( pair2 == cluster1 ) ) || ( pair2 == cluster2 ) ) { queueIterator . remove ( ) ; } } FastIDSet merged = new FastIDSet ( ( ( cluster1 . size ( ) ) + ( cluster2 . size ( ) ) ) ) ; merged . addAll ( cluster1 ) ; merged . addAll ( cluster2 ) ; for ( FastIDSet cluster : clusters ) { double similarity = clusterSimilarity . getSimilarity ( merged , cluster ) ; <START_BUG> if ( similarity > ( queue . get ( ( ( queue . size ( ) ) - 1 ) ) . getSimilarity ( ) ) ) { <END_BUG> ListIterator < TreeClusteringRecommender2 . ClusterClusterPair > queueIterator = queue . listIterator ( ) ; while ( queueIterator . hasNext ( ) ) { if ( similarity > ( queueIterator . next ( ) . getSimilarity ( ) ) ) { queueIterator . previous ( ) ; break ; } } queueIterator . add ( new TreeClusteringRecommender2 . ClusterClusterPair ( merged , cluster , similarity ) ) ; } } clusters . add ( merged ) ; } return done ; } private List < TreeClusteringRecommender2 . ClusterClusterPair > findClosestClusters ( int numUsers , List < FastIDSet > clusters ) throws TasteException { } private FastByIDMap < List < RecommendedItem > > computeTopRecsPerUserID ( Iterable < FastIDSet > clusters ) throws TasteException { } private List < RecommendedItem > computeTopRecsForCluster ( FastIDSet cluster ) throws TasteException { } private static FastByIDMap < FastIDSet > computeClustersPerUserID ( Collection < FastIDSet > clusters ) { } @ Override public void refresh ( Collection < Refreshable > alreadyRefreshed ) { } @ Override public String toString ( ) { } private final class Estimator implements TopItems . Estimator < Long > { private final FastIDSet cluster ; private Estimator ( FastIDSet cluster ) { } @ Override public double estimate ( Long itemID ) throws TasteException { } } }

Fix:
if ( ( ( queue . size ( ) ) > 0 ) && ( similarity > ( queue . get ( ( ( queue . size ( ) ) - 1 ) ) . getSimilarity ( ) ) ) ) {