Program: 107905
Project: 107905
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);
  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() ? 1 : 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);
  }
  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;
  final String[] list=getDistinctValues(column);
  final String attribute=handle.getAttributeName(column);
  final DataType<?> datatype=handle.getDataType(attribute);
  final int level=handle.getGeneralization(attribute);
  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);
  }
  return list;
}