Program: 178151
Project: 178151
Buggy source:
public void sort() throws TimeoutException {
  long timer=System.nanoTime();
  InvTweaksContainerManager globalContainer=new InvTweaksContainerManager(mc);
  if (algorithm != ALGORITHM_DEFAULT) {
    if (algorithm == ALGORITHM_INVENTORY) {
      log.info("String_Node_Str");
      if (globalContainer.hasSection(InvTweaksContainerSection.CRAFTING_IN)) {
        List<yu> craftingSlots=globalContainer.getSlots(InvTweaksContainerSection.CRAFTING_IN);
        int emptyIndex=globalContainer.getFirstEmptyIndex(InvTweaksContainerSection.INVENTORY);
        if (emptyIndex != -1) {
          for (          yu craftingSlot : craftingSlots) {
            if (hasStack(craftingSlot)) {
              globalContainer.move(InvTweaksContainerSection.CRAFTING_IN,globalContainer.getSlotIndex(getSlotNumber(craftingSlot)),InvTweaksContainerSection.INVENTORY,emptyIndex);
              emptyIndex=globalContainer.getFirstEmptyIndex(InvTweaksContainerSection.INVENTORY);
              if (emptyIndex == -1) {
                break;
              }
            }
          }
        }
      }
      log.info("String_Node_Str");
      for (int i=size - 1; i >= 0; i--) {
        aan from=containerMgr.getItemStack(i);
        if (from != null) {
          yr fromItem=getItem(from);
          if (isDamageable(fromItem)) {
            if (sortArmorParts) {
              if (isItemArmor(fromItem)) {
                ql fromItemArmor=(ql)fromItem;
                if (globalContainer.hasSection(InvTweaksContainerSection.ARMOR)) {
                  List<yu> armorSlots=globalContainer.getSlots(InvTweaksContainerSection.ARMOR);
                  for (                  yu slot : armorSlots) {
                    boolean move=false;
                    if (!hasStack(slot)) {
                      move=true;
                    }
 else {
                      int armorLevel=getArmorLevel((ql)getItem(getStack(slot)));
                      if (armorLevel < getArmorLevel(fromItemArmor) || (armorLevel == getArmorLevel(fromItemArmor) && getItemDamage(getStack(slot)) < getItemDamage(from))) {
                        move=true;
                      }
                    }
                    if (isItemValid(slot,from) && move) {
                      globalContainer.move(InvTweaksContainerSection.INVENTORY,i,InvTweaksContainerSection.ARMOR,globalContainer.getSlotIndex(getSlotNumber(slot)));
                    }
                  }
                }
              }
            }
          }
 else {
            int j=0;
            for (            Integer lockPriority : lockPriorities) {
              if (lockPriority > 0) {
                aan to=containerMgr.getItemStack(j);
                if (to != null && areItemsEqual(from,to)) {
                  move(i,j,Integer.MAX_VALUE);
                  markAsNotMoved(j);
                  if (containerMgr.getItemStack(i) == null) {
                    break;
                  }
                }
              }
              j++;
            }
          }
        }
      }
    }
    log.info("String_Node_Str");
    Iterator<InvTweaksConfigSortingRule> rulesIt=rules.iterator();
    while (rulesIt.hasNext()) {
      InvTweaksConfigSortingRule rule=rulesIt.next();
      int rulePriority=rule.getPriority();
      if (log.getLevel() == InvTweaksConst.DEBUG)       log.info("String_Node_Str" + rule.getKeyword() + "String_Node_Str"+ rulePriority+ "String_Node_Str");
      for (int i=0; i < size; i++) {
        aan from=containerMgr.getItemStack(i);
        if (hasToBeMoved(i) && lockPriorities[i] < rulePriority) {
          List<InvTweaksItemTreeItem> fromItems=tree.getItems(getItemID(from),getItemDamage(from));
          if (tree.matches(fromItems,rule.getKeyword())) {
            int[] preferredSlots=rule.getPreferredSlots();
            int stackToMove=i;
            for (int j=0; j < preferredSlots.length; j++) {
              int k=preferredSlots[j];
              int moveResult=move(stackToMove,k,rulePriority);
              if (moveResult != -1) {
                if (moveResult == k) {
                  break;
                }
 else {
                  from=containerMgr.getItemStack(moveResult);
                  fromItems=tree.getItems(getItemID(from),getItemDamage(from));
                  if (!tree.matches(fromItems,rule.getKeyword())) {
                    break;
                  }
 else {
                    stackToMove=moveResult;
                    j=-1;
                  }
                }
              }
            }
          }
        }
      }
    }
    log.info("String_Node_Str");
    for (int i=0; i < size; i++) {
      if (hasToBeMoved(i) && lockPriorities[i] > 0) {
        markAsMoved(i,1);
      }
    }
  }
  defaultSorting();
  if (log.getLevel() == InvTweaksConst.DEBUG) {
    timer=System.nanoTime() - timer;
    log.info("String_Node_Str" + timer + "String_Node_Str");
  }
}

Fixed version (ground truth):
public void sort() throws TimeoutException {
  long timer=System.nanoTime();
  InvTweaksContainerManager globalContainer=new InvTweaksContainerManager(mc);
  if (getHoldStack() != null) {
    int emptySlot=globalContainer.getFirstEmptyIndex(InvTweaksContainerSection.INVENTORY);
    if (emptySlot != -1) {
      globalContainer.putHoldItemDown(InvTweaksContainerSection.INVENTORY,emptySlot);
    }
 else {
      return;
    }
  }
  if (algorithm != ALGORITHM_DEFAULT) {
    if (algorithm == ALGORITHM_INVENTORY) {
      log.info("String_Node_Str");
      if (globalContainer.hasSection(InvTweaksContainerSection.CRAFTING_IN)) {
        List<yu> craftingSlots=globalContainer.getSlots(InvTweaksContainerSection.CRAFTING_IN);
        int emptyIndex=globalContainer.getFirstEmptyIndex(InvTweaksContainerSection.INVENTORY);
        if (emptyIndex != -1) {
          for (          yu craftingSlot : craftingSlots) {
            if (hasStack(craftingSlot)) {
              globalContainer.move(InvTweaksContainerSection.CRAFTING_IN,globalContainer.getSlotIndex(getSlotNumber(craftingSlot)),InvTweaksContainerSection.INVENTORY,emptyIndex);
              emptyIndex=globalContainer.getFirstEmptyIndex(InvTweaksContainerSection.INVENTORY);
              if (emptyIndex == -1) {
                break;
              }
            }
          }
        }
      }
      log.info("String_Node_Str");
      for (int i=size - 1; i >= 0; i--) {
        aan from=containerMgr.getItemStack(i);
        if (from != null) {
          yr fromItem=getItem(from);
          if (isDamageable(fromItem)) {
            if (sortArmorParts) {
              if (isItemArmor(fromItem)) {
                ql fromItemArmor=(ql)fromItem;
                if (globalContainer.hasSection(InvTweaksContainerSection.ARMOR)) {
                  List<yu> armorSlots=globalContainer.getSlots(InvTweaksContainerSection.ARMOR);
                  for (                  yu slot : armorSlots) {
                    boolean move=false;
                    if (!hasStack(slot)) {
                      move=true;
                    }
 else {
                      int armorLevel=getArmorLevel((ql)getItem(getStack(slot)));
                      if (armorLevel < getArmorLevel(fromItemArmor) || (armorLevel == getArmorLevel(fromItemArmor) && getItemDamage(getStack(slot)) < getItemDamage(from))) {
                        move=true;
                      }
                    }
                    if (isItemValid(slot,from) && move) {
                      globalContainer.move(InvTweaksContainerSection.INVENTORY,i,InvTweaksContainerSection.ARMOR,globalContainer.getSlotIndex(getSlotNumber(slot)));
                    }
                  }
                }
              }
            }
          }
 else {
            int j=0;
            for (            Integer lockPriority : lockPriorities) {
              if (lockPriority > 0) {
                aan to=containerMgr.getItemStack(j);
                if (to != null && areItemsEqual(from,to)) {
                  move(i,j,Integer.MAX_VALUE);
                  markAsNotMoved(j);
                  if (containerMgr.getItemStack(i) == null) {
                    break;
                  }
                }
              }
              j++;
            }
          }
        }
      }
    }
    log.info("String_Node_Str");
    Iterator<InvTweaksConfigSortingRule> rulesIt=rules.iterator();
    while (rulesIt.hasNext()) {
      InvTweaksConfigSortingRule rule=rulesIt.next();
      int rulePriority=rule.getPriority();
      if (log.getLevel() == InvTweaksConst.DEBUG)       log.info("String_Node_Str" + rule.getKeyword() + "String_Node_Str"+ rulePriority+ "String_Node_Str");
      for (int i=0; i < size; i++) {
        aan from=containerMgr.getItemStack(i);
        if (hasToBeMoved(i) && lockPriorities[i] < rulePriority) {
          List<InvTweaksItemTreeItem> fromItems=tree.getItems(getItemID(from),getItemDamage(from));
          if (tree.matches(fromItems,rule.getKeyword())) {
            int[] preferredSlots=rule.getPreferredSlots();
            int stackToMove=i;
            for (int j=0; j < preferredSlots.length; j++) {
              int k=preferredSlots[j];
              int moveResult=move(stackToMove,k,rulePriority);
              if (moveResult != -1) {
                if (moveResult == k) {
                  break;
                }
 else {
                  from=containerMgr.getItemStack(moveResult);
                  fromItems=tree.getItems(getItemID(from),getItemDamage(from));
                  if (!tree.matches(fromItems,rule.getKeyword())) {
                    break;
                  }
 else {
                    stackToMove=moveResult;
                    j=-1;
                  }
                }
              }
            }
          }
        }
      }
    }
    log.info("String_Node_Str");
    for (int i=0; i < size; i++) {
      if (hasToBeMoved(i) && lockPriorities[i] > 0) {
        markAsMoved(i,1);
      }
    }
  }
  defaultSorting();
  if (log.getLevel() == InvTweaksConst.DEBUG) {
    timer=System.nanoTime() - timer;
    log.info("String_Node_Str" + timer + "String_Node_Str");
  }
}