Program: 57834
Project: 57834
Buggy source:
public static void sortNodeList(final List<DatanodeDescriptor> nodes,String field,String order){
class NodeComapare implements Comparator<DatanodeDescriptor> {
    static final int FIELD_NAME=1, FIELD_LAST_CONTACT=2, FIELD_BLOCKS=3, FIELD_CAPACITY=4, FIELD_USED=5, FIELD_PERCENT_USED=6, FIELD_NONDFS_USED=7, FIELD_REMAINING=8, FIELD_PERCENT_REMAINING=9, FIELD_ADMIN_STATE=10, FIELD_DECOMMISSIONED=11, FIELD_BLOCKPOOL_USED=12, FIELD_PERBLOCKPOOL_USED=13, FIELD_FAILED_VOLUMES=14, SORT_ORDER_ASC=1, SORT_ORDER_DSC=2;
    int sortField=FIELD_NAME;
    int sortOrder=SORT_ORDER_ASC;
    public NodeComapare(    String field,    String order){
      if (field.equals("String_Node_Str")) {
        sortField=FIELD_LAST_CONTACT;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_CAPACITY;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_USED;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_NONDFS_USED;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_REMAINING;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_PERCENT_USED;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_PERCENT_REMAINING;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_BLOCKS;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_ADMIN_STATE;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_DECOMMISSIONED;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_BLOCKPOOL_USED;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_PERBLOCKPOOL_USED;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_FAILED_VOLUMES;
      }
 else {
        sortField=FIELD_NAME;
      }
      if (order.equals("String_Node_Str")) {
        sortOrder=SORT_ORDER_DSC;
      }
 else {
        sortOrder=SORT_ORDER_ASC;
      }
    }
    @Override public int compare(    DatanodeDescriptor d1,    DatanodeDescriptor d2){
      int ret=0;
switch (sortField) {
case FIELD_LAST_CONTACT:
        ret=(int)(d2.getLastUpdate() - d1.getLastUpdate());
      break;
case FIELD_CAPACITY:
    long dlong=d1.getCapacity() - d2.getCapacity();
  ret=(dlong < 0) ? -1 : ((dlong > 0) ? 1 : 0);
break;
case FIELD_USED:
dlong=d1.getDfsUsed() - d2.getDfsUsed();
ret=(dlong < 0) ? -1 : ((dlong > 0) ? 1 : 0);
break;
case FIELD_NONDFS_USED:
dlong=d1.getNonDfsUsed() - d2.getNonDfsUsed();
ret=(dlong < 0) ? -1 : ((dlong > 0) ? 1 : 0);
break;
case FIELD_REMAINING:
dlong=d1.getRemaining() - d2.getRemaining();
ret=(dlong < 0) ? -1 : ((dlong > 0) ? 1 : 0);
break;
case FIELD_PERCENT_USED:
double ddbl=((d1.getDfsUsedPercent()) - (d2.getDfsUsedPercent()));
ret=(ddbl < 0) ? -1 : ((ddbl > 0) ? 1 : 0);
break;
case FIELD_PERCENT_REMAINING:
ddbl=((d1.getRemainingPercent()) - (d2.getRemainingPercent()));
ret=(ddbl < 0) ? -1 : ((ddbl > 0) ? 1 : 0);
break;
case FIELD_BLOCKS:
ret=d1.numBlocks() - d2.numBlocks();
break;
case FIELD_ADMIN_STATE:
ret=d1.getAdminState().toString().compareTo(d2.getAdminState().toString());
break;
case FIELD_DECOMMISSIONED:
ret=DFSUtil.DECOM_COMPARATOR.compare(d1,d2);
break;
case FIELD_NAME:
ret=d1.getHostName().compareTo(d2.getHostName());
break;
case FIELD_BLOCKPOOL_USED:
dlong=d1.getBlockPoolUsed() - d2.getBlockPoolUsed();
ret=(dlong < 0) ? -1 : ((dlong > 0) ? 1 : 0);
break;
case FIELD_PERBLOCKPOOL_USED:
ddbl=d1.getBlockPoolUsedPercent() - d2.getBlockPoolUsedPercent();
ret=(ddbl < 0) ? -1 : ((ddbl > 0) ? 1 : 0);
break;
case FIELD_FAILED_VOLUMES:
int dint=d1.getVolumeFailures() - d2.getVolumeFailures();
ret=(dint < 0) ? -1 : ((dint > 0) ? 1 : 0);
break;
}
return (sortOrder == SORT_ORDER_DSC) ? -ret : ret;
}
}
Collections.sort(nodes,new NodeComapare(field,order));
}

Fixed version (ground truth):
public static void sortNodeList(final List<DatanodeDescriptor> nodes,String field,String order){
class NodeComapare implements Comparator<DatanodeDescriptor> {
    static final int FIELD_NAME=1, FIELD_LAST_CONTACT=2, FIELD_BLOCKS=3, FIELD_CAPACITY=4, FIELD_USED=5, FIELD_PERCENT_USED=6, FIELD_NONDFS_USED=7, FIELD_REMAINING=8, FIELD_PERCENT_REMAINING=9, FIELD_ADMIN_STATE=10, FIELD_DECOMMISSIONED=11, FIELD_BLOCKPOOL_USED=12, FIELD_PERBLOCKPOOL_USED=13, FIELD_FAILED_VOLUMES=14, SORT_ORDER_ASC=1, SORT_ORDER_DSC=2;
    int sortField=FIELD_NAME;
    int sortOrder=SORT_ORDER_ASC;
    public NodeComapare(    String field,    String order){
      if (field.equals("String_Node_Str")) {
        sortField=FIELD_LAST_CONTACT;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_CAPACITY;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_USED;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_NONDFS_USED;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_REMAINING;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_PERCENT_USED;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_PERCENT_REMAINING;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_BLOCKS;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_ADMIN_STATE;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_DECOMMISSIONED;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_BLOCKPOOL_USED;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_PERBLOCKPOOL_USED;
      }
 else       if (field.equals("String_Node_Str")) {
        sortField=FIELD_FAILED_VOLUMES;
      }
 else {
        sortField=FIELD_NAME;
      }
      if (order.equals("String_Node_Str")) {
        sortOrder=SORT_ORDER_DSC;
      }
 else {
        sortOrder=SORT_ORDER_ASC;
      }
    }
    @Override public int compare(    DatanodeDescriptor d1,    DatanodeDescriptor d2){
      int ret=0;
switch (sortField) {
case FIELD_LAST_CONTACT:
        ret=(int)(d2.getLastUpdate() - d1.getLastUpdate());
      break;
case FIELD_CAPACITY:
    long dlong=d1.getCapacity() - d2.getCapacity();
  ret=(dlong < 0) ? -1 : ((dlong > 0) ? 1 : 0);
break;
case FIELD_USED:
dlong=d1.getDfsUsed() - d2.getDfsUsed();
ret=(dlong < 0) ? -1 : ((dlong > 0) ? 1 : 0);
break;
case FIELD_NONDFS_USED:
dlong=d1.getNonDfsUsed() - d2.getNonDfsUsed();
ret=(dlong < 0) ? -1 : ((dlong > 0) ? 1 : 0);
break;
case FIELD_REMAINING:
dlong=d1.getRemaining() - d2.getRemaining();
ret=(dlong < 0) ? -1 : ((dlong > 0) ? 1 : 0);
break;
case FIELD_PERCENT_USED:
double ddbl=((d1.getDfsUsedPercent()) - (d2.getDfsUsedPercent()));
ret=(ddbl < 0) ? -1 : ((ddbl > 0) ? 1 : 0);
break;
case FIELD_PERCENT_REMAINING:
ddbl=((d1.getRemainingPercent()) - (d2.getRemainingPercent()));
ret=(ddbl < 0) ? -1 : ((ddbl > 0) ? 1 : 0);
break;
case FIELD_BLOCKS:
ret=d1.numBlocks() - d2.numBlocks();
break;
case FIELD_ADMIN_STATE:
ret=d1.getAdminState().toString().compareTo(d2.getAdminState().toString());
break;
case FIELD_DECOMMISSIONED:
ret=DFSUtil.DECOM_COMPARATOR.compare(d1,d2);
break;
case FIELD_NAME:
ret=d1.getHostName().compareTo(d2.getHostName());
break;
case FIELD_BLOCKPOOL_USED:
dlong=d1.getBlockPoolUsed() - d2.getBlockPoolUsed();
ret=(dlong < 0) ? -1 : ((dlong > 0) ? 1 : 0);
break;
case FIELD_PERBLOCKPOOL_USED:
ddbl=d1.getBlockPoolUsedPercent() - d2.getBlockPoolUsedPercent();
ret=(ddbl < 0) ? -1 : ((ddbl > 0) ? 1 : 0);
break;
case FIELD_FAILED_VOLUMES:
int dint=d1.getVolumeFailures() - d2.getVolumeFailures();
ret=(dint < 0) ? -1 : ((dint > 0) ? 1 : 0);
break;
default :
throw new IllegalArgumentException("String_Node_Str");
}
return (sortOrder == SORT_ORDER_DSC) ? -ret : ret;
}
}
Collections.sort(nodes,new NodeComapare(field,order));
}