Program: 58407
Project: 58407
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=HeatMapRenderStyle.MIN_SELECTED_FIELD_HEIGHT;
  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 / totalNumberOfElements;
  float hmMinSpacing=HeatMapRenderStyle.MIN_SELECTED_FIELD_HEIGHT * 1.5f;
  float resultingFocusSpacing=0;
  float resultingNormalSpacing=0;
  int minSizeGranted=0;
  int elementsInOverhead=0;
  int selectedElementsInOverhead=0;
  for (  Group group : selectedGroups.keySet()) {
    GLHeatMap heatMap=heatMapWrapper.getHeatMap(group.getGroupIndex());
    int numElements=heatMap.getNumberOfVisibleElements();
    if (numElements * defaultSpacing < hmMinSpacing) {
      minSizeGranted++;
      elementsInOverhead+=numElements;
      if (heatMap.isForceMinSpacing())       selectedElementsInOverhead+=numElements;
    }
  }
  if (minSizeGranted > 0) {
    availableSpaceForHeatMaps-=hmMinSpacing * minSizeGranted;
    totalNumberOfElements-=elementsInOverhead;
    numberOfFocusElements-=selectedElementsInOverhead;
    defaultSpacing=availableSpaceForHeatMaps / (float)(totalNumberOfElements);
  }
  if (layout.isUseZoom() && numberOfFocusElements > 0) {
    if (defaultSpacing > requestedFocusSpacing) {
      resultingFocusSpacing=defaultSpacing;
      resultingNormalSpacing=defaultSpacing;
    }
 else     if ((availableSpaceForHeatMaps - (numberOfFocusElements * requestedFocusSpacing)) > availableSpaceForHeatMaps / 2) {
      resultingFocusSpacing=requestedFocusSpacing;
      resultingNormalSpacing=(availableSpaceForHeatMaps - resultingFocusSpacing * numberOfFocusElements) / (totalNumberOfElements - numberOfFocusElements);
    }
 else {
      resultingFocusSpacing=(availableSpaceForHeatMaps / 2) / numberOfFocusElements;
      resultingNormalSpacing=(availableSpaceForHeatMaps / 2) / (totalNumberOfElements - numberOfFocusElements);
    }
  }
 else {
    resultingNormalSpacing=defaultSpacing;
    resultingFocusSpacing=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=HeatMapRenderStyle.MIN_SELECTED_FIELD_HEIGHT;
  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 / totalNumberOfElements;
  float hmMinSpacing=HeatMapRenderStyle.MIN_SELECTED_FIELD_HEIGHT * 1.5f;
  float resultingFocusSpacing=0;
  float resultingNormalSpacing=0;
  int minSizeGranted=0;
  int elementsInOverhead=0;
  int selectedElementsInOverhead=0;
  for (  Group group : selectedGroups.keySet()) {
    GLHeatMap heatMap=heatMapWrapper.getHeatMap(group.getGroupIndex());
    int numElements=heatMap.getNumberOfVisibleElements();
    if (numElements * defaultSpacing < hmMinSpacing) {
      minSizeGranted++;
      elementsInOverhead+=numElements;
      if (heatMap.isForceMinSpacing())       selectedElementsInOverhead+=numElements;
    }
  }
  if (minSizeGranted > 0) {
    availableSpaceForHeatMaps-=hmMinSpacing * minSizeGranted;
    totalNumberOfElements-=elementsInOverhead;
    numberOfFocusElements-=selectedElementsInOverhead;
    defaultSpacing=availableSpaceForHeatMaps / (float)(totalNumberOfElements);
  }
  if (layout.isUseZoom() && numberOfFocusElements > 0) {
    if (defaultSpacing > requestedFocusSpacing) {
      resultingFocusSpacing=defaultSpacing;
      resultingNormalSpacing=defaultSpacing;
    }
 else     if ((availableSpaceForHeatMaps - (numberOfFocusElements * requestedFocusSpacing)) > availableSpaceForHeatMaps / 2) {
      resultingFocusSpacing=requestedFocusSpacing;
      resultingNormalSpacing=(availableSpaceForHeatMaps - resultingFocusSpacing * numberOfFocusElements) / (totalNumberOfElements - numberOfFocusElements);
    }
 else {
      resultingFocusSpacing=(availableSpaceForHeatMaps / 3) / numberOfFocusElements;
      resultingNormalSpacing=(availableSpaceForHeatMaps / 3 * 2) / (totalNumberOfElements - numberOfFocusElements);
    }
  }
 else {
    resultingNormalSpacing=defaultSpacing;
    resultingFocusSpacing=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);
  }
}