Program: 58764
Project: 58764
Buggy source:
/** 
 * The palcluster routine performs clustering using pairwise average linking on the given distance matrix.
 * @param set
 * @return index of virtual array
 */
private Integer palcluster(EClustererType eClustererType){
  int[] clusterid=new int[iNrSamples];
  int[] number=new int[iNrSamples];
  Node[] result=new Node[iNrSamples - 1];
  for (int j=0; j < iNrSamples; j++) {
    number[j]=1;
    clusterid[j]=j;
  }
  int j;
  ClosestPair pair=null;
  ArrayList<Integer> AlIndexes=new ArrayList<Integer>();
  float[][] distmatrix;
  try {
    distmatrix=new float[iNrSamples][iNrSamples];
  }
 catch (  OutOfMemoryError e) {
    return -1;
  }
  distmatrix=similarities.clone();
  int iPercentage=1;
  if (eClustererType == EClustererType.GENE_CLUSTERING)   GeneralManager.get().getEventPublisher().triggerEvent(new RenameProgressBarEvent("String_Node_Str"));
 else   GeneralManager.get().getEventPublisher().triggerEvent(new RenameProgressBarEvent("String_Node_Str"));
  for (int n=iNrSamples; n > 1; n--) {
    if (bClusteringCanceled == false) {
      int sum;
      int is=1;
      int js=0;
      int tempPercentage=(int)((float)(iNrSamples - n) / iNrSamples * 100);
      if (iPercentage == tempPercentage) {
        GeneralManager.get().getEventPublisher().triggerEvent(new ClusterProgressEvent(iPercentage,false));
        iPercentage++;
      }
      pair=find_closest_pair(n,distmatrix);
      if (pair.update) {
        is=pair.x;
        js=pair.y;
      }
      Node node=new Node();
      node.setCorrelation(pair.correlation);
      node.setLeft(clusterid[is]);
      node.setRight(clusterid[js]);
      result[iNrSamples - n]=node;
      sum=number[is] + number[js];
      for (j=0; j < js; j++) {
        distmatrix[js][j]=distmatrix[is][j] * number[is] + distmatrix[js][j] * number[js];
        distmatrix[js][j]/=sum;
      }
      for (j=js + 1; j < is; j++) {
        distmatrix[j][js]=distmatrix[is][j] * number[is] + distmatrix[j][js] * number[js];
        distmatrix[j][js]/=sum;
      }
      for (j=is + 1; j < n; j++) {
        distmatrix[j][js]=distmatrix[j][is] * number[is] + distmatrix[j][js] * number[js];
        distmatrix[j][js]/=sum;
      }
      for (j=0; j < is; j++)       distmatrix[is][j]=distmatrix[n - 1][j];
      for (j=is + 1; j < n - 1; j++)       distmatrix[j][is]=distmatrix[n - 1][j];
      number[js]=sum;
      number[is]=number[n - 1];
      clusterid[js]=n - iNrSamples - 1;
      clusterid[is]=clusterid[n - 1];
      processEvents();
    }
 else {
      GeneralManager.get().getEventPublisher().triggerEvent(new ClusterProgressEvent(100,true));
      return -2;
    }
  }
  for (int i=0; i < result.length; i++) {
    if (result[i].getLeft() >= 0)     AlIndexes.add(result[i].getLeft());
    if (result[i].getRight() >= 0)     AlIndexes.add(result[i].getRight());
  }
  tree=new Tree<ClusterNode>();
  int random=(int)((Math.random() * Integer.MAX_VALUE) + 1);
  ClusterNode node=new ClusterNode("String_Node_Str",random,0f,0,true);
  tree.setRootNode(node);
  treeStructureToTree(node,result,result.length - 1,eClustererType);
  ClusterHelper.determineNrElements(tree);
  ClusterHelper.determineHierarchyDepth(tree);
  determineExpressionValue(eClustererType);
  AlIndexes=getAl();
  if (eClustererType == EClustererType.GENE_CLUSTERING)   set.setClusteredTreeGenes(tree);
 else   set.setClusteredTreeExps(tree);
  Integer clusteredVAId=set.createStorageVA(AlIndexes);
  GeneralManager.get().getEventPublisher().triggerEvent(new ClusterProgressEvent(iProgressBarMultiplier * 50 + iProgressBarOffsetValue,true));
  return clusteredVAId;
}

Fixed version (ground truth):
/** 
 * The palcluster routine performs clustering using pairwise average linking on the given distance matrix.
 * @param set
 * @return index of virtual array
 */
private Integer palcluster(EClustererType eClustererType){
  int[] clusterid=new int[iNrSamples];
  int[] number=new int[iNrSamples];
  Node[] result=new Node[iNrSamples - 1];
  for (int j=0; j < iNrSamples; j++) {
    number[j]=1;
    clusterid[j]=j;
  }
  int j;
  ClosestPair pair=null;
  ArrayList<Integer> AlIndexes=new ArrayList<Integer>();
  float[][] distmatrix;
  try {
    distmatrix=new float[iNrSamples][iNrSamples];
  }
 catch (  OutOfMemoryError e) {
    return -1;
  }
  distmatrix=similarities.clone();
  int iPercentage=1;
  if (eClustererType == EClustererType.GENE_CLUSTERING)   GeneralManager.get().getEventPublisher().triggerEvent(new RenameProgressBarEvent("String_Node_Str"));
 else   GeneralManager.get().getEventPublisher().triggerEvent(new RenameProgressBarEvent("String_Node_Str"));
  for (int n=iNrSamples; n > 1; n--) {
    if (bClusteringCanceled == false) {
      int sum;
      int is=1;
      int js=0;
      int tempPercentage=(int)((float)(iNrSamples - n) / iNrSamples * 100);
      if (iPercentage == tempPercentage) {
        GeneralManager.get().getEventPublisher().triggerEvent(new ClusterProgressEvent(iPercentage,false));
        iPercentage++;
      }
      pair=find_closest_pair(n,distmatrix);
      if (pair.update) {
        is=pair.x;
        js=pair.y;
      }
      Node node=new Node();
      node.setCorrelation(pair.correlation);
      node.setLeft(clusterid[is]);
      node.setRight(clusterid[js]);
      result[iNrSamples - n]=node;
      sum=number[is] + number[js];
      for (j=0; j < js; j++) {
        distmatrix[js][j]=distmatrix[is][j] * number[is] + distmatrix[js][j] * number[js];
        distmatrix[js][j]/=sum;
      }
      for (j=js + 1; j < is; j++) {
        distmatrix[j][js]=distmatrix[is][j] * number[is] + distmatrix[j][js] * number[js];
        distmatrix[j][js]/=sum;
      }
      for (j=is + 1; j < n; j++) {
        distmatrix[j][js]=distmatrix[j][is] * number[is] + distmatrix[j][js] * number[js];
        distmatrix[j][js]/=sum;
      }
      for (j=0; j < is; j++)       distmatrix[is][j]=distmatrix[n - 1][j];
      for (j=is + 1; j < n - 1; j++)       distmatrix[j][is]=distmatrix[n - 1][j];
      number[js]=sum;
      number[is]=number[n - 1];
      clusterid[js]=n - iNrSamples - 1;
      clusterid[is]=clusterid[n - 1];
      processEvents();
    }
 else {
      GeneralManager.get().getEventPublisher().triggerEvent(new ClusterProgressEvent(100,true));
      return -2;
    }
  }
  for (int i=0; i < result.length; i++) {
    if (result[i].getLeft() >= 0)     AlIndexes.add(result[i].getLeft());
    if (result[i].getRight() >= 0)     AlIndexes.add(result[i].getRight());
  }
  tree=new Tree<ClusterNode>();
  int random=(int)((Math.random() * Integer.MAX_VALUE) + 1);
  ClusterNode node=new ClusterNode("String_Node_Str",random,0f,0,true);
  tree.setRootNode(node);
  treeStructureToTree(node,result,result.length - 1,eClustererType);
  ClusterHelper.determineNrElements(tree);
  ClusterHelper.determineHierarchyDepth(tree);
  determineExpressionValue(eClustererType);
  AlIndexes=getAl();
  if (eClustererType == EClustererType.GENE_CLUSTERING)   set.setClusteredTreeGenes(tree);
 else   set.setClusteredTreeExps(tree);
  Integer clusteredVAId=0;
  if (eClustererType == EClustererType.GENE_CLUSTERING)   clusteredVAId=set.createStorageVA(AlIndexes);
 else   if (eClustererType == EClustererType.EXPERIMENTS_CLUSTERING)   clusteredVAId=set.createSetVA(AlIndexes);
  GeneralManager.get().getEventPublisher().triggerEvent(new ClusterProgressEvent(iProgressBarMultiplier * 50 + iProgressBarOffsetValue,true));
  return clusteredVAId;
}