#vulnerable code 
                             public void agglomerate(LinkageStrategy linkageStrategy) {
		Collections.sort(distances);
		if (distances.size() > 0) {
			ClusterPair minDistLink = distances.remove(0);
			clusters.remove(minDistLink.getrCluster());
			clusters.remove(minDistLink.getlCluster());

			Cluster oldClusterL = minDistLink.getlCluster();
			Cluster oldClusterR = minDistLink.getrCluster();
			Cluster newCluster = minDistLink.agglomerate(null);

			for (Cluster iClust : clusters) {
				ClusterPair link1 = findByClusters(iClust, oldClusterL);
				ClusterPair link2 = findByClusters(iClust, oldClusterR);
				ClusterPair newLinkage = new ClusterPair();
				newLinkage.setlCluster(iClust);
				newLinkage.setrCluster(newCluster);
				Collection<Double> distanceValues = new ArrayList<Double>();
				if (link1 != null) {
					distanceValues.add(link1.getLinkageDistance());
					distances.remove(link1);
				}
				if (link1 != null) {
					distanceValues.add(link2.getLinkageDistance());
					distances.remove(link2);
				}
				Double newDistance = linkageStrategy
				        .calculateDistance(distanceValues);
				newLinkage.setLinkageDistance(newDistance);
				distances.add(newLinkage);

			}
			clusters.add(newCluster);
		}
	} 
                            #location 24 
                            #vulnerability type NULL_DEREFERENCE
#fixed code
                             public void agglomerate(LinkageStrategy linkageStrategy) {
		Collections.sort(distances);
		if (distances.size() > 0) {
			ClusterPair minDistLink = distances.remove(0);
			clusters.remove(minDistLink.getrCluster());
			clusters.remove(minDistLink.getlCluster());

			Cluster oldClusterL = minDistLink.getlCluster();
			Cluster oldClusterR = minDistLink.getrCluster();
			Cluster newCluster = minDistLink.agglomerate(null);

			for (Cluster iClust : clusters) {
				ClusterPair link1 = findByClusters(iClust, oldClusterL);
				ClusterPair link2 = findByClusters(iClust, oldClusterR);
				ClusterPair newLinkage = new ClusterPair();
				newLinkage.setlCluster(iClust);
				newLinkage.setrCluster(newCluster);
				Collection<Double> distanceValues = new ArrayList<Double>();
				if (link1 != null) {
					distanceValues.add(link1.getLinkageDistance());
					distances.remove(link1);
				}
				if (link2 != null) {
					distanceValues.add(link2.getLinkageDistance());
					distances.remove(link2);
				}
				Double newDistance = linkageStrategy
				        .calculateDistance(distanceValues);
				newLinkage.setLinkageDistance(newDistance);
				distances.add(newLinkage);

			}
			clusters.add(newCluster);
		}
	}