Program: 178160
Project: 178160
Buggy source:
/** 
 * Tries to move a stack from i to j, and swaps them if j is already occupied but i is of greater priority (even if they are of same ID).
 * @param i from slot
 * @param j to slot
 * @param priority  The rule priority. Use 1 if the stack was not moved using a rule.
 * @return -1 if it failed,j if the stacks were merged into one, n if the j stack has been moved to the n slot.
 * @throws TimeoutException
 */
private int move(int i,int j,int priority) throws TimeoutException {
  yq from=containerMgr.getItemStack(i);
  yq to=containerMgr.getItemStack(j);
  if (from == null || frozenSlots[j] || frozenSlots[i]) {
    return -1;
  }
  if (lockPriorities[i] <= priority) {
    if (i == j) {
      markAsMoved(i,priority);
      return j;
    }
    if (to == null && lockPriorities[j] <= priority && !frozenSlots[j]) {
      rulePriority[i]=-1;
      keywordOrder[i]=-1;
      rulePriority[j]=priority;
      keywordOrder[j]=getItemOrder(from);
      containerMgr.move(i,j);
      return j;
    }
 else     if (to != null) {
      boolean canBeSwappedOrMerged=false;
      if (getStackSize(from) <= getMaxStackSize(from) && getStackSize(to) <= getMaxStackSize(to)) {
        if (lockPriorities[j] <= priority) {
          if (rulePriority[j] < priority) {
            canBeSwappedOrMerged=true;
          }
 else           if (rulePriority[j] == priority) {
            if (isOrderedBefore(i,j)) {
              canBeSwappedOrMerged=true;
            }
          }
        }
        if (!canBeSwappedOrMerged && areItemsEqual(from,to) && getStackSize(to) < getMaxStackSize(to)) {
          canBeSwappedOrMerged=true;
        }
      }
      if (canBeSwappedOrMerged) {
        keywordOrder[j]=keywordOrder[i];
        rulePriority[j]=priority;
        rulePriority[i]=-1;
        rulePriority[i]=-1;
        containerMgr.move(i,j);
        yq remains=containerMgr.getItemStack(i);
        if (remains != null) {
          int dropSlot=i;
          if (lockPriorities[j] > lockPriorities[i]) {
            for (int k=0; k < size; k++) {
              if (containerMgr.getItemStack(k) == null && lockPriorities[k] == 0) {
                dropSlot=k;
                break;
              }
            }
          }
          if (dropSlot != i) {
            containerMgr.move(i,dropSlot);
          }
          rulePriority[dropSlot]=-1;
          keywordOrder[dropSlot]=getItemOrder(remains);
          return dropSlot;
        }
 else {
          return j;
        }
      }
    }
  }
  return -1;
}

Fixed version (ground truth):
/** 
 * Tries to move a stack from i to j, and swaps them if j is already occupied but i is of greater priority (even if they are of same ID).
 * @param i from slot
 * @param j to slot
 * @param priority  The rule priority. Use 1 if the stack was not moved using a rule.
 * @return -1 if it failed,j if the stacks were merged into one, n if the j stack has been moved to the n slot.
 * @throws TimeoutException
 */
private int move(int i,int j,int priority) throws TimeoutException {
  yq from=containerMgr.getItemStack(i);
  yq to=containerMgr.getItemStack(j);
  if (from == null || frozenSlots[j] || frozenSlots[i]) {
    return -1;
  }
  if (lockPriorities[i] <= priority) {
    if (i == j) {
      markAsMoved(i,priority);
      return j;
    }
    if (to == null && lockPriorities[j] <= priority && !frozenSlots[j]) {
      rulePriority[i]=-1;
      keywordOrder[i]=-1;
      rulePriority[j]=priority;
      keywordOrder[j]=getItemOrder(from);
      containerMgr.move(i,j);
      return j;
    }
 else     if (to != null) {
      boolean canBeSwappedOrMerged=false;
      if (lockPriorities[j] <= priority) {
        if (rulePriority[j] < priority) {
          canBeSwappedOrMerged=true;
        }
 else         if (rulePriority[j] == priority) {
          if (isOrderedBefore(i,j)) {
            canBeSwappedOrMerged=true;
          }
        }
      }
      if (areItemsEqual(from,to)) {
        if (getStackSize(to) < getMaxStackSize(to)) {
          canBeSwappedOrMerged=true;
        }
 else         if (getStackSize(from) > getMaxStackSize(from)) {
          canBeSwappedOrMerged=false;
        }
      }
      if (canBeSwappedOrMerged) {
        keywordOrder[j]=keywordOrder[i];
        rulePriority[j]=priority;
        rulePriority[i]=-1;
        rulePriority[i]=-1;
        containerMgr.move(i,j);
        yq remains=containerMgr.getItemStack(i);
        if (remains != null) {
          int dropSlot=i;
          if (lockPriorities[j] > lockPriorities[i]) {
            for (int k=0; k < size; k++) {
              if (containerMgr.getItemStack(k) == null && lockPriorities[k] == 0) {
                dropSlot=k;
                break;
              }
            }
          }
          if (dropSlot != i) {
            containerMgr.move(i,dropSlot);
          }
          rulePriority[dropSlot]=-1;
          keywordOrder[dropSlot]=getItemOrder(remains);
          return dropSlot;
        }
 else {
          return j;
        }
      }
    }
  }
  return -1;
}