Program: 71835
Project: 71835
Buggy source:
protected int[] formalize(DimensionType[] columns,int tableWidth){
  ArrayList percentageList=new ArrayList();
  ArrayList unsetList=new ArrayList();
  int[] resolvedColumnWidth=new int[columns.length];
  double total=0.0f;
  int fixedLength=0;
  for (int i=0; i < columns.length; i++) {
    if (columns[i] == null) {
      unsetList.add(new Integer(i));
    }
 else     if (EngineIRConstants.UNITS_PERCENTAGE.equals(columns[i].getUnits())) {
      percentageList.add(new Integer(i));
      total+=columns[i].getMeasure();
    }
 else     if (EngineIRConstants.UNITS_EM.equals(columns[i].getUnits()) || EngineIRConstants.UNITS_EX.equals(columns[i].getUnits())) {
      int len=TableLayout.this.getDimensionValue(columns[i],PropertyUtil.getDimensionValue(table.getComputedStyle().getProperty(StyleConstants.STYLE_FONT_SIZE)));
      resolvedColumnWidth[i]=len;
      fixedLength+=len;
    }
 else {
      int len=TableLayout.this.getDimensionValue(columns[i],tableWidth);
      resolvedColumnWidth[i]=len;
      fixedLength+=len;
    }
  }
  if (unsetList.isEmpty() && percentageList.isEmpty()) {
    return resolvedColumnWidth;
  }
  if (fixedLength >= tableWidth) {
    for (int i=0; i < unsetList.size(); i++) {
      Integer index=(Integer)unsetList.get(i);
      columns[index.intValue()]=new DimensionType(0d,EngineIRConstants.UNITS_PT);
      resolvedColumnWidth[index.intValue()]=0;
    }
    for (int i=0; i < percentageList.size(); i++) {
      Integer index=(Integer)percentageList.get(i);
      columns[index.intValue()]=new DimensionType(0d,EngineIRConstants.UNITS_PT);
      resolvedColumnWidth[index.intValue()]=0;
    }
  }
 else {
    float leftPercentage=(((float)(tableWidth - fixedLength)) / tableWidth) * 100.0f;
    if (unsetList.isEmpty()) {
      double ratio=leftPercentage / total;
      for (int i=0; i < percentageList.size(); i++) {
        Integer index=(Integer)percentageList.get(i);
        columns[index.intValue()]=new DimensionType(columns[index.intValue()].getMeasure() * ratio,columns[index.intValue()].getUnits());
        resolvedColumnWidth[index.intValue()]=TableLayout.this.getDimensionValue(columns[index.intValue()],tableWidth);
      }
    }
 else {
      if (total < leftPercentage) {
        double delta=leftPercentage - total;
        for (int i=0; i < unsetList.size(); i++) {
          Integer index=(Integer)unsetList.get(i);
          columns[index.intValue()]=new DimensionType(delta / (double)unsetList.size(),EngineIRConstants.UNITS_PERCENTAGE);
          resolvedColumnWidth[index.intValue()]=TableLayout.this.getDimensionValue(columns[index.intValue()],tableWidth);
        }
        for (int i=0; i < percentageList.size(); i++) {
          Integer index=(Integer)percentageList.get(i);
          columns[index.intValue()]=new DimensionType(columns[index.intValue()].getMeasure(),columns[index.intValue()].getUnits());
          resolvedColumnWidth[index.intValue()]=TableLayout.this.getDimensionValue(columns[index.intValue()],tableWidth);
        }
      }
 else {
        double ratio=leftPercentage / total;
        for (int i=0; i < unsetList.size(); i++) {
          Integer index=(Integer)unsetList.get(i);
          columns[index.intValue()]=new DimensionType(0d,EngineIRConstants.UNITS_PT);
          resolvedColumnWidth[index.intValue()]=0;
        }
        for (int i=0; i < percentageList.size(); i++) {
          Integer index=(Integer)percentageList.get(i);
          columns[index.intValue()]=new DimensionType(columns[index.intValue()].getMeasure() * ratio,columns[index.intValue()].getUnits());
          resolvedColumnWidth[index.intValue()]=TableLayout.this.getDimensionValue(columns[index.intValue()],tableWidth);
        }
      }
    }
  }
  return resolvedColumnWidth;
}

Fixed version (ground truth):
/** 
 * Calculates the column width for the table. the return value should be each column width in point.
 * @param columns The column width specified in report design.
 * @param tableWidth The suggested table width. If isTableWidthDefined is true, this value is user defined table width; otherwise, it is the max possible width for the table.
 * @param isTableWidthDefined The flag to indicate whether the table width has been defined explicitly.
 * @return each column width in point.
 */
protected int[] formalize(DimensionType[] columns,int tableWidth,boolean isTableWidthDefined){
  ArrayList percentageList=new ArrayList();
  ArrayList unsetList=new ArrayList();
  ArrayList preFixedList=new ArrayList();
  int[] resolvedColumnWidth=new int[columns.length];
  double total=0.0f;
  int fixedLength=0;
  for (int i=0; i < columns.length; i++) {
    if (columns[i] == null) {
      unsetList.add(new Integer(i));
    }
 else     if (EngineIRConstants.UNITS_PERCENTAGE.equals(columns[i].getUnits())) {
      percentageList.add(new Integer(i));
      total+=columns[i].getMeasure();
    }
 else     if (EngineIRConstants.UNITS_EM.equals(columns[i].getUnits()) || EngineIRConstants.UNITS_EX.equals(columns[i].getUnits())) {
      int len=TableLayout.this.getDimensionValue(columns[i],PropertyUtil.getDimensionValue(table.getComputedStyle().getProperty(StyleConstants.STYLE_FONT_SIZE)));
      resolvedColumnWidth[i]=len;
      fixedLength+=len;
    }
 else {
      int len=TableLayout.this.getDimensionValue(columns[i],tableWidth);
      resolvedColumnWidth[i]=len;
      preFixedList.add(new Integer(i));
      fixedLength+=len;
    }
  }
  if (!isTableWidthDefined && unsetList.isEmpty() && percentageList.isEmpty()) {
    return resolvedColumnWidth;
  }
  if (fixedLength >= tableWidth) {
    for (int i=0; i < unsetList.size(); i++) {
      Integer index=(Integer)unsetList.get(i);
      resolvedColumnWidth[index.intValue()]=0;
    }
    for (int i=0; i < percentageList.size(); i++) {
      Integer index=(Integer)percentageList.get(i);
      resolvedColumnWidth[index.intValue()]=0;
    }
    return resolvedColumnWidth;
  }
  if (unsetList.isEmpty()) {
    if (percentageList.isEmpty()) {
      int left=tableWidth - fixedLength;
      int delta=left / preFixedList.size();
      for (int i=0; i < preFixedList.size(); i++) {
        Integer index=(Integer)preFixedList.get(i);
        resolvedColumnWidth[index.intValue()]+=delta;
      }
    }
 else {
      float leftPercentage=(((float)(tableWidth - fixedLength)) / tableWidth) * 100.0f;
      double ratio=leftPercentage / total;
      for (int i=0; i < percentageList.size(); i++) {
        Integer index=(Integer)percentageList.get(i);
        columns[index.intValue()]=new DimensionType(columns[index.intValue()].getMeasure() * ratio,columns[index.intValue()].getUnits());
        resolvedColumnWidth[index.intValue()]=TableLayout.this.getDimensionValue(columns[index.intValue()],tableWidth);
      }
    }
  }
 else {
    if (percentageList.isEmpty()) {
      int left=tableWidth - fixedLength;
      int eachWidth=left / unsetList.size();
      for (int i=0; i < unsetList.size(); i++) {
        Integer index=(Integer)unsetList.get(i);
        resolvedColumnWidth[index.intValue()]=eachWidth;
      }
    }
 else {
      float leftPercentage=(((float)(tableWidth - fixedLength)) / tableWidth) * 100.0f;
      if (leftPercentage <= total) {
        double ratio=leftPercentage / total;
        for (int i=0; i < unsetList.size(); i++) {
          Integer index=(Integer)unsetList.get(i);
          resolvedColumnWidth[index.intValue()]=0;
        }
        for (int i=0; i < percentageList.size(); i++) {
          Integer index=(Integer)percentageList.get(i);
          columns[index.intValue()]=new DimensionType(columns[index.intValue()].getMeasure() * ratio,columns[index.intValue()].getUnits());
          resolvedColumnWidth[index.intValue()]=TableLayout.this.getDimensionValue(columns[index.intValue()],tableWidth);
        }
      }
 else {
        int usedLength=fixedLength;
        for (int i=0; i < percentageList.size(); i++) {
          Integer index=(Integer)percentageList.get(i);
          int width=TableLayout.this.getDimensionValue(columns[index.intValue()],tableWidth);
          usedLength+=width;
          resolvedColumnWidth[index.intValue()]=width;
        }
        int left=tableWidth - usedLength;
        int eachWidth=left / unsetList.size();
        for (int i=0; i < unsetList.size(); i++) {
          Integer index=(Integer)unsetList.get(i);
          resolvedColumnWidth[index.intValue()]=eachWidth;
        }
      }
    }
  }
  return resolvedColumnWidth;
}