Program: 178159
Project: 178159
Buggy source:
public void sort() throws TimeoutException {
  long timer=System.nanoTime();
  InvTweaksContainerManager globalContainer=new InvTweaksContainerManager(mc);
  if (isMultiplayerWorld()) {
    putHoldItemDown();
  }
  if (algorithm != ALGORITHM_DEFAULT) {
    if (algorithm == ALGORITHM_INVENTORY) {
      log.info("String_Node_Str");
      if (globalContainer.hasSection(InvTweaksContainerSection.CRAFTING_IN)) {
        List<wz> craftingSlots=globalContainer.getSlots(InvTweaksContainerSection.CRAFTING_IN);
        int emptyIndex=globalContainer.getFirstEmptyIndex(InvTweaksContainerSection.INVENTORY);
        if (emptyIndex != -1) {
          for (          wz 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--) {
        yq from=containerMgr.getItemStack(i);
        if (from != null) {
          if (sortArmorParts) {
            ww fromItem=getItem(from);
            if (isDamageable(fromItem)) {
              if (isItemArmor(fromItem)) {
                po fromItemArmor=(po)fromItem;
                if (globalContainer.hasSection(InvTweaksContainerSection.ARMOR)) {
                  List<wz> armorSlots=globalContainer.getSlots(InvTweaksContainerSection.ARMOR);
                  for (                  wz slot : armorSlots) {
                    if (isItemValid(slot,from) && (!hasStack(slot) || getArmorLevel(fromItemArmor) > getArmorLevel(((po)getItem(getStack(slot)))))) {
                      globalContainer.move(InvTweaksContainerSection.INVENTORY,i,InvTweaksContainerSection.ARMOR,globalContainer.getSlotIndex(getSlotNumber(slot)));
                    }
                  }
                }
              }
            }
          }
 else {
            int j=0;
            for (            Integer lockPriority : lockPriorities) {
              if (lockPriority > 0) {
                yq 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++) {
        yq 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 (isMultiplayerWorld()) {
    putHoldItemDown();
  }
  if (algorithm != ALGORITHM_DEFAULT) {
    if (algorithm == ALGORITHM_INVENTORY) {
      log.info("String_Node_Str");
      if (globalContainer.hasSection(InvTweaksContainerSection.CRAFTING_IN)) {
        List<wz> craftingSlots=globalContainer.getSlots(InvTweaksContainerSection.CRAFTING_IN);
        int emptyIndex=globalContainer.getFirstEmptyIndex(InvTweaksContainerSection.INVENTORY);
        if (emptyIndex != -1) {
          for (          wz 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--) {
        yq from=containerMgr.getItemStack(i);
        if (from != null) {
          ww fromItem=getItem(from);
          if (isDamageable(fromItem)) {
            if (sortArmorParts) {
              if (isItemArmor(fromItem)) {
                po fromItemArmor=(po)fromItem;
                if (globalContainer.hasSection(InvTweaksContainerSection.ARMOR)) {
                  List<wz> armorSlots=globalContainer.getSlots(InvTweaksContainerSection.ARMOR);
                  for (                  wz slot : armorSlots) {
                    if (isItemValid(slot,from) && (!hasStack(slot) || getArmorLevel(fromItemArmor) > getArmorLevel(((po)getItem(getStack(slot)))))) {
                      globalContainer.move(InvTweaksContainerSection.INVENTORY,i,InvTweaksContainerSection.ARMOR,globalContainer.getSlotIndex(getSlotNumber(slot)));
                    }
                  }
                }
              }
            }
          }
 else {
            int j=0;
            for (            Integer lockPriority : lockPriorities) {
              if (lockPriority > 0) {
                yq 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++) {
        yq 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");
  }
}