Program: 107822
Project: 107822
Buggy source:
/** 
 * Returns an ordered list of the distinct set of data items from the given column. This method assumes that the order of string data items can (and should) be derived from the provided hierarchy
 * @param column The column
 * @param hierarchy The hierarchy, may be null
 * @return
 */
public String[] getDistinctValuesOrdered(int column,String[][] hierarchy){
  interrupt.value=false;
  final String[] list=getDistinctValues(column);
  final String attribute=handle.getAttributeName(column);
  final DataType<?> datatype=handle.getDataType(attribute);
  final int level=handle.getGeneralization(attribute);
  progress.value=20;
  if (hierarchy == null || level == 0) {
    sort(list,datatype);
  }
 else {
    final Map<String,Integer> order=new HashMap<String,Integer>();
    int max=0;
    Set<String> baseSet=new HashSet<String>();
    DataType<?> baseType=handle.getBaseDataType(attribute);
    for (int i=0; i < hierarchy.length; i++) {
      String element=hierarchy[i][0];
      checkInterrupt();
      if (baseType.isValid(element))       baseSet.add(element);
    }
    String[] baseArray=baseSet.toArray(new String[baseSet.size()]);
    sort(baseArray,handle.getBaseDataType(attribute));
    Map<String,Integer> baseOrder=new HashMap<String,Integer>();
    for (int i=0; i < baseArray.length; i++) {
      checkInterrupt();
      baseOrder.put(baseArray[i],i);
    }
    int lower=handle.isOptimized() ? 0 : level;
    int upper=handle.isOptimized() ? hierarchy[0].length : level + 1;
    for (int i=0; i < hierarchy.length; i++) {
      checkInterrupt();
      for (int j=lower; j < upper; j++) {
        if (!order.containsKey(hierarchy[i][j])) {
          Integer position=baseOrder.get(hierarchy[i][0]);
          if (position != null) {
            order.put(hierarchy[i][j],position);
            max=Math.max(position,max) + 1;
          }
        }
      }
    }
    order.put(DataType.ANY_VALUE,max);
    sort(list,order);
  }
  progress.value=40;
  return list;
}

Fixed version (ground truth):
/** 
 * Returns an ordered list of the distinct set of data items from the given column. This method assumes that the order of string data items can (and should) be derived from the provided hierarchy
 * @param column The column
 * @param hierarchy The hierarchy, may be null
 * @return
 */
public String[] getDistinctValuesOrdered(int column,String[][] hierarchy){
  interrupt.value=false;
  String[] list=getDistinctValues(column);
  String attribute=handle.getAttributeName(column);
  DataType<?> datatype=handle.getDataType(attribute);
  int level=handle.getGeneralization(attribute);
  progress.value=20;
  if ((datatype instanceof DataTypeWithRatioScale) || hierarchy == null || level == 0) {
    sort(list,datatype);
  }
 else {
    Map<String,Integer> order=new HashMap<String,Integer>();
    int max=0;
    Set<String> baseSet=new HashSet<String>();
    DataType<?> baseType=handle.getBaseDataType(attribute);
    for (int i=0; i < hierarchy.length; i++) {
      String element=hierarchy[i][0];
      checkInterrupt();
      if (baseType.isValid(element))       baseSet.add(element);
    }
    String[] baseArray=baseSet.toArray(new String[baseSet.size()]);
    sort(baseArray,handle.getBaseDataType(attribute));
    Map<String,Integer> baseOrder=new HashMap<String,Integer>();
    for (int i=0; i < baseArray.length; i++) {
      checkInterrupt();
      baseOrder.put(baseArray[i],i);
    }
    int lower=handle.isOptimized() ? 0 : level;
    int upper=handle.isOptimized() ? hierarchy[0].length : level + 1;
    for (int i=0; i < hierarchy.length; i++) {
      checkInterrupt();
      for (int j=lower; j < upper; j++) {
        if (!order.containsKey(hierarchy[i][j])) {
          Integer position=baseOrder.get(hierarchy[i][0]);
          if (position != null) {
            order.put(hierarchy[i][j],position);
            max=Math.max(position,max) + 1;
          }
        }
      }
    }
    order.put(DataType.ANY_VALUE,max);
    progress.value=30;
    boolean allCovered=true;
    for (    String value : list) {
      if (!order.containsKey(value)) {
        allCovered=false;
        break;
      }
    }
    progress.value=35;
    if (allCovered) {
      sort(list,order);
    }
 else {
      sort(list);
    }
  }
  progress.value=40;
  return list;
}