Program: 58428
Project: 58428
Buggy source:
protected void calculateDetailHeatMapHeights(){
  hashHeatMapHeights.clear();
  HeatMapWrapper heatMapWrapper=layout.getHeatMapWrapper();
  HashMap<Group,GroupInfo> selectedGroups=heatMapWrapper.getSelectedGroups();
  int totalNumberOfElements=0;
  int numberOfFocusElements=0;
  float requestedFocusSpacing=0;
  float totalHeatMapOverheadSize=0;
  for (  Group group : selectedGroups.keySet()) {
    GLHeatMap heatMap=heatMapWrapper.getHeatMap(group.getGroupIndex());
    int numElements=heatMap.getNumberOfVisibleElements();
    totalNumberOfElements+=numElements;
    totalHeatMapOverheadSize+=heatMap.getRequiredOverheadSpacing();
    if (heatMap.isForceMinSpacing()) {
      numberOfFocusElements+=numElements;
      requestedFocusSpacing=heatMap.getMinSpacing();
    }
  }
  float availableSpaceForHeatMaps=getDetailHeight() - (getDetailHeight() * DETAIL_HEATMAP_GAP_PORTION * (selectedGroups.size() - 1)) - totalHeatMapOverheadSize;
  float defaultSpacing=availableSpaceForHeatMaps / (float)totalNumberOfElements;
  float minSpacing=defaultSpacing / 10.0f;
  float hmMinSpacing=HeatMapRenderStyle.MIN_SELECTED_FIELD_HEIGHT * 1.5f;
  float resultingFocusSpacing=0;
  float resultingNormalSpacing=0;
  int overheadsGranted=0;
  int elementsInOverhead=0;
  for (  Group group : selectedGroups.keySet()) {
    GLHeatMap heatMap=heatMapWrapper.getHeatMap(group.getGroupIndex());
    int numElements=heatMap.getNumberOfVisibleElements();
    if (numElements * defaultSpacing < hmMinSpacing) {
      overheadsGranted++;
      elementsInOverhead+=numElements;
    }
  }
  availableSpaceForHeatMaps-=hmMinSpacing * overheadsGranted - (elementsInOverhead * defaultSpacing);
  defaultSpacing=availableSpaceForHeatMaps / (float)(totalNumberOfElements);
  minSpacing=defaultSpacing / 4;
  if (layout.isUseZoom() && numberOfFocusElements > 0) {
    if (defaultSpacing > requestedFocusSpacing) {
      resultingFocusSpacing=defaultSpacing;
      resultingNormalSpacing=defaultSpacing;
    }
 else     if ((availableSpaceForHeatMaps - (numberOfFocusElements * requestedFocusSpacing)) / (totalNumberOfElements - numberOfFocusElements) > minSpacing) {
      resultingFocusSpacing=requestedFocusSpacing;
      resultingNormalSpacing=(availableSpaceForHeatMaps - resultingFocusSpacing * numberOfFocusElements) / (totalNumberOfElements - numberOfFocusElements);
    }
 else {
      resultingNormalSpacing=minSpacing;
      resultingFocusSpacing=(availableSpaceForHeatMaps - (totalNumberOfElements - numberOfFocusElements) * resultingNormalSpacing) / numberOfFocusElements;
    }
  }
 else {
    resultingNormalSpacing=defaultSpacing;
  }
  for (  Group group : selectedGroups.keySet()) {
    GLHeatMap heatMap=heatMapWrapper.getHeatMap(group.getGroupIndex());
    int numElements=heatMap.getNumberOfVisibleElements();
    float currentHeatMapOverheadSize=heatMap.getRequiredOverheadSpacing();
    float size=0;
    if (layout.isUseZoom() && heatMap.isForceMinSpacing()) {
      size=(resultingFocusSpacing * numElements) + currentHeatMapOverheadSize;
    }
 else {
      size=(resultingNormalSpacing * numElements) + currentHeatMapOverheadSize;
    }
    if (size - currentHeatMapOverheadSize < hmMinSpacing)     size=hmMinSpacing + currentHeatMapOverheadSize;
    hashHeatMapHeights.put(group.getGroupIndex(),size);
  }
}

Fixed version (ground truth):
protected void calculateDetailHeatMapHeights(){
  hashHeatMapHeights.clear();
  HeatMapWrapper heatMapWrapper=layout.getHeatMapWrapper();
  HashMap<Group,GroupInfo> selectedGroups=heatMapWrapper.getSelectedGroups();
  int totalNumberOfElements=0;
  int numberOfFocusElements=0;
  float requestedFocusSpacing=0;
  float totalHeatMapOverheadSize=0;
  for (  Group group : selectedGroups.keySet()) {
    GLHeatMap heatMap=heatMapWrapper.getHeatMap(group.getGroupIndex());
    int numElements=heatMap.getNumberOfVisibleElements();
    totalNumberOfElements+=numElements;
    totalHeatMapOverheadSize+=heatMap.getRequiredOverheadSpacing();
    if (heatMap.isForceMinSpacing()) {
      numberOfFocusElements+=numElements;
      requestedFocusSpacing=heatMap.getMinSpacing();
    }
  }
  float gapSpace=getDetailHeight() * DETAIL_HEATMAP_SPACING_PORTION_DEFAULT * (selectedGroups.size() - 1);
  detailHeatMapSpacing=getDetailHeight() * DETAIL_HEATMAP_SPACING_PORTION_DEFAULT;
  float availableSpaceForHeatMaps=getDetailHeight() - gapSpace - totalHeatMapOverheadSize;
  float defaultSpacing=availableSpaceForHeatMaps / (float)totalNumberOfElements;
  float minSpacing=defaultSpacing / 10.0f;
  float hmMinSpacing=HeatMapRenderStyle.MIN_SELECTED_FIELD_HEIGHT * 1.5f;
  float resultingFocusSpacing=0;
  float resultingNormalSpacing=0;
  int overheadsGranted=0;
  int elementsInOverhead=0;
  for (  Group group : selectedGroups.keySet()) {
    GLHeatMap heatMap=heatMapWrapper.getHeatMap(group.getGroupIndex());
    int numElements=heatMap.getNumberOfVisibleElements();
    if (numElements * defaultSpacing < hmMinSpacing) {
      overheadsGranted++;
      elementsInOverhead+=numElements;
    }
  }
  availableSpaceForHeatMaps-=hmMinSpacing * overheadsGranted - (elementsInOverhead * defaultSpacing);
  defaultSpacing=availableSpaceForHeatMaps / (float)(totalNumberOfElements);
  minSpacing=defaultSpacing / 4;
  if (layout.isUseZoom() && numberOfFocusElements > 0) {
    if (defaultSpacing > requestedFocusSpacing) {
      resultingFocusSpacing=defaultSpacing;
      resultingNormalSpacing=defaultSpacing;
    }
 else     if ((availableSpaceForHeatMaps - (numberOfFocusElements * requestedFocusSpacing)) / (totalNumberOfElements - numberOfFocusElements) > minSpacing) {
      resultingFocusSpacing=requestedFocusSpacing;
      resultingNormalSpacing=(availableSpaceForHeatMaps - resultingFocusSpacing * numberOfFocusElements) / (totalNumberOfElements - numberOfFocusElements);
    }
 else {
      resultingNormalSpacing=minSpacing;
      resultingFocusSpacing=(availableSpaceForHeatMaps - (totalNumberOfElements - numberOfFocusElements) * resultingNormalSpacing) / numberOfFocusElements;
    }
  }
 else {
    resultingNormalSpacing=defaultSpacing;
  }
  for (  Group group : selectedGroups.keySet()) {
    GLHeatMap heatMap=heatMapWrapper.getHeatMap(group.getGroupIndex());
    int numElements=heatMap.getNumberOfVisibleElements();
    float currentHeatMapOverheadSize=heatMap.getRequiredOverheadSpacing();
    float size=0;
    if (layout.isUseZoom() && heatMap.isForceMinSpacing()) {
      size=(resultingFocusSpacing * numElements) + currentHeatMapOverheadSize;
    }
 else {
      size=(resultingNormalSpacing * numElements) + currentHeatMapOverheadSize;
    }
    if (size - currentHeatMapOverheadSize < hmMinSpacing)     size=hmMinSpacing + currentHeatMapOverheadSize;
    hashHeatMapHeights.put(group.getGroupIndex(),size);
  }
}