Program: 29916
Project: 29916
Buggy source:
private static SortOrder BuildSort(Context context,TableDefinition definition){
  if (context == null)   throw new IllegalArgumentException("String_Node_Str");
  if (context.items.isEmpty())   return null;
  SortOrder result=new SortOrder();
  ArrayList<Item> items=extractTokens(context);
  TableDefinition tableDef=definition;
  boolean fieldDetected=false;
  for (int i=0; i < items.size(); i++) {
    Item item=items.get(i);
    if (item.item.getType().equals(SemanticNames.DESC)) {
      result.ascending=false;
      continue;
    }
    if (item.item.getType().equals(SemanticNames.ASC)) {
      result.ascending=true;
      continue;
    }
    if (fieldDetected)     throw new IllegalArgumentException("String_Node_Str" + QueryUtils.FullLinkName(result.items));
    AggregationGroupItem ai=new AggregationGroupItem();
    if (result.items == null)     result.items=new ArrayList<AggregationGroupItem>();
    result.items.add(ai);
    ai.name=item.item.getValue();
    if (tableDef != null) {
      FieldDefinition fd=tableDef.getFieldDef(ai.name);
      ai.fieldDef=fd;
      if (fd == null) {
        if (i != (items.size() - 1)) {
          throw new IllegalArgumentException("String_Node_Str" + QueryUtils.FullLinkName(result.items));
        }
        if (!QueryUtils.isSystemField(ai.name)) {
          throw new IllegalArgumentException("String_Node_Str" + ai.name);
        }
      }
      if (tableDef.isLinkField(ai.name)) {
        ai.isLink=true;
        if (fieldDetected)         throw new IllegalArgumentException("String_Node_Str" + QueryUtils.FullLinkName(result.items));
        tableDef=tableDef.getLinkExtentTableDef(fd);
        if (tableDef == null) {
          throw new IllegalArgumentException("String_Node_Str" + QueryUtils.FullLinkName(result.items));
        }
      }
 else {
        if (fd != null && fd.getType() == FieldType.GROUP)         throw new IllegalArgumentException("String_Node_Str");
        fieldDetected=true;
      }
      ai.tableDef=tableDef;
    }
  }
  if (!fieldDetected)   throw new IllegalArgumentException("String_Node_Str");
  return result;
}

Fixed version (ground truth):
private static SortOrder BuildSort(Context context,TableDefinition definition){
  if (context == null)   throw new IllegalArgumentException("String_Node_Str");
  if (context.items.isEmpty())   return null;
  SortOrder result=new SortOrder();
  ArrayList<Item> items=extractTokens(context);
  TableDefinition tableDef=definition;
  boolean fieldDetected=false;
  for (int i=0; i < items.size(); i++) {
    Item item=items.get(i);
    if (item.item.getType().equals(SemanticNames.DESC)) {
      result.ascending=false;
      continue;
    }
    if (item.item.getType().equals(SemanticNames.ASC)) {
      result.ascending=true;
      continue;
    }
    if (fieldDetected)     throw new IllegalArgumentException("String_Node_Str" + QueryUtils.FullLinkName(result.items));
    AggregationGroupItem ai=new AggregationGroupItem();
    if (result.items == null)     result.items=new ArrayList<AggregationGroupItem>();
    result.items.add(ai);
    ai.name=item.item.getValue();
    if (tableDef != null) {
      FieldDefinition fd=tableDef.getFieldDef(ai.name);
      ai.fieldDef=fd;
      if (fd == null) {
        if (i != (items.size() - 1)) {
          throw new IllegalArgumentException("String_Node_Str" + QueryUtils.FullLinkName(result.items));
        }
        if (!QueryUtils.isSystemField(ai.name)) {
          throw new IllegalArgumentException("String_Node_Str" + ai.name);
        }
      }
      if (tableDef.isLinkField(ai.name) || (fd != null && fd.isXLinkField())) {
        ai.isLink=true;
        if (fieldDetected)         throw new IllegalArgumentException("String_Node_Str" + QueryUtils.FullLinkName(result.items));
        tableDef=tableDef.getLinkExtentTableDef(fd);
        if (tableDef == null) {
          throw new IllegalArgumentException("String_Node_Str" + QueryUtils.FullLinkName(result.items));
        }
      }
 else {
        if (fd != null && fd.getType() == FieldType.GROUP)         throw new IllegalArgumentException("String_Node_Str");
        fieldDetected=true;
      }
      ai.tableDef=tableDef;
    }
  }
  if (!fieldDetected)   throw new IllegalArgumentException("String_Node_Str");
  return result;
}