Program: 178184
Project: 178184
Buggy source:
/** 
 * Autoreplace + middle click sorting
 */
public void autoReplaceSlot(int slot,int wantedId,int wantedDamage){
  InvTweaksInventory inventory=new InvTweaksInventory(mc,config.getLockPriorities());
  ItemStack candidateStack, replacementStack=null;
  ItemStack storedStack=createItemStack(wantedId,1,wantedDamage);
  int selectedStackId=-1;
  for (int i=0; i < InvTweaks.INVENTORY_SIZE; i++) {
    candidateStack=inventory.getItemStack(i);
    if (candidateStack != null && inventory.areSameItem(storedStack,candidateStack) && config.canBeAutoReplaced(getItemID(candidateStack),getItemDamage(candidateStack))) {
      if (replacementStack == null || getStackSize(replacementStack) > getStackSize(candidateStack) || (getStackSize(replacementStack) == getStackSize(candidateStack) && getMaxStackSize(replacementStack) == 1 && getItemDamage(replacementStack) < getItemDamage(candidateStack))) {
        replacementStack=candidateStack;
        selectedStackId=i;
      }
    }
  }
  if (replacementStack != null) {
    log.info("String_Node_Str");
    new Thread(new Runnable(){
      private InvTweaksInventory inventory;
      private int currentItem;
      private int i, expectedItemId;
      public Runnable init(      InvTweaksInventory inventory,      int i,      int currentItem){
        this.inventory=inventory;
        this.currentItem=currentItem;
        this.expectedItemId=getItemID(inventory.getItemStack(i));
        this.i=i;
        return this;
      }
      public void run(){
        if (isMultiplayerWorld()) {
          int pollingTime=0;
          setHasInventoryChanged(false);
          while (!hasInventoryChanged() && pollingTime < POLLING_TIMEOUT) {
            trySleep(POLLING_DELAY);
          }
          if (pollingTime < AUTOREPLACE_DELAY)           trySleep(AUTOREPLACE_DELAY - pollingTime);
          if (pollingTime >= POLLING_TIMEOUT)           log.warning("String_Node_Str");
        }
 else {
          trySleep(AUTOREPLACE_DELAY);
        }
        try {
          ItemStack stack=inventory.getItemStack(i);
          if (stack != null && getItemID(stack) == expectedItemId) {
            inventory.moveStack(i,currentItem,Integer.MAX_VALUE);
          }
        }
 catch (        NullPointerException e) {
        }
      }
    }
.init(inventory,selectedStackId,wantedId)).start();
  }
}

Fixed version (ground truth):
/** 
 * Autoreplace + middle click sorting
 */
public void autoReplaceSlot(int slot,int wantedId,int wantedDamage){
  InvTweaksInventory inventory=new InvTweaksInventory(mc,config.getLockPriorities());
  ItemStack candidateStack, replacementStack=null;
  ItemStack storedStack=createItemStack(wantedId,1,wantedDamage);
  int replacementStackSlot=-1;
  for (int i=0; i < InvTweaks.INVENTORY_SIZE; i++) {
    candidateStack=inventory.getItemStack(i);
    if (candidateStack != null && inventory.areSameItem(storedStack,candidateStack) && config.canBeAutoReplaced(getItemID(candidateStack),getItemDamage(candidateStack))) {
      if (replacementStack == null || getStackSize(replacementStack) > getStackSize(candidateStack) || (getStackSize(replacementStack) == getStackSize(candidateStack) && getMaxStackSize(replacementStack) == 1 && getItemDamage(replacementStack) < getItemDamage(candidateStack))) {
        replacementStack=candidateStack;
        replacementStackSlot=i;
      }
    }
  }
  if (replacementStack != null) {
    log.info("String_Node_Str");
    new Thread(new Runnable(){
      private InvTweaksInventory inventory;
      private int targetedSlot;
      private int i, expectedItemId;
      public Runnable init(      InvTweaksInventory inventory,      int i,      int currentItem){
        this.inventory=inventory;
        this.targetedSlot=currentItem;
        this.expectedItemId=getItemID(inventory.getItemStack(i));
        this.i=i;
        return this;
      }
      public void run(){
        if (isMultiplayerWorld()) {
          int pollingTime=0;
          setHasInventoryChanged(false);
          while (!hasInventoryChanged() && pollingTime < POLLING_TIMEOUT) {
            trySleep(POLLING_DELAY);
          }
          if (pollingTime < AUTOREPLACE_DELAY)           trySleep(AUTOREPLACE_DELAY - pollingTime);
          if (pollingTime >= POLLING_TIMEOUT)           log.warning("String_Node_Str");
        }
 else {
          trySleep(AUTOREPLACE_DELAY);
        }
        try {
          ItemStack stack=inventory.getItemStack(i);
          if (stack != null && getItemID(stack) == expectedItemId) {
            inventory.moveStack(i,targetedSlot,Integer.MAX_VALUE);
          }
        }
 catch (        NullPointerException e) {
        }
      }
    }
.init(inventory,replacementStackSlot,slot)).start();
  }
}