Program: 156626
Project: 156626
Buggy source:
private boolean attemptCrafting(ItemStack input){
  if (inventoryPublic.getStackInSlot(11) != null) {
    return false;
  }
  if (input == null || input.stackSize == 0 || !(input.getItem() == Items.paper || input.getItem() instanceof ItemPackage)) {
    return false;
  }
  if (input.getItem() instanceof ItemPackage) {
    NBTTagCompound inputTag=NBTUtils.getItemData(input);
    for (int i=0; i < 9; i++) {
      if (isPatternSlotSet(i) && inputTag.hasKey("String_Node_Str" + i)) {
        return false;
      }
    }
  }
  TObjectIntHashMap<Requirement> reqCounts=new TObjectIntHashMap<Requirement>(9);
  int missingCount=0;
  int filteredReqsToFulfill=0;
  for (int i=0; i < 9; i++) {
    if (isPatternSlotSet(i)) {
      ItemStack inputStack=inventoryPattern.getStackInSlot(i);
      if (inputStack != null) {
        filteredReqsToFulfill++;
      }
 else {
        missingCount++;
        requirements[i]=null;
        continue;
      }
      Requirement r=requirements[i];
      if (r == null) {
        continue;
      }
      if (!r.isValid()) {
        requirements[i]=null;
        continue;
      }
      if (r.getStack() == null) {
        requirements[i]=null;
        continue;
      }
      if (inputStack != null) {
        if (!StackHelper.isMatchingItem(inputStack,r.getStack(),true,false)) {
          requirements[i]=null;
          continue;
        }
      }
      reqCounts.adjustOrPutValue(requirements[i],1,1);
      filteredReqsToFulfill--;
    }
 else {
      requirements[i]=null;
    }
  }
  for (  Requirement r : reqCounts.keys(new Requirement[reqCounts.size()])) {
    if (r.getStack().stackSize < reqCounts.get(r)) {
      int allowedAmount=0;
      for (int i=0; i < 9; i++) {
        if (requirements[i] != null && requirements[i].equals(r)) {
          allowedAmount--;
          if (allowedAmount < 0) {
            requirements[i]=null;
            filteredReqsToFulfill++;
          }
        }
      }
      reqCounts.remove(r);
    }
  }
  if (filteredReqsToFulfill > 0) {
    for (int i=0; i < 9; i++) {
      if (filteredReqsToFulfill == 0) {
        break;
      }
      if (isPatternSlotSet(i) && requirements[i] == null) {
        ItemStack inputStack=inventoryPattern.getStackInSlot(i);
        if (inputStack != null) {
          for (int j=0; j < 9; j++) {
            ItemStack comparedStack=inventoryPublic.getStackInSlot(j);
            if (comparedStack == null) {
              continue;
            }
            Requirement r=new Requirement(this,j);
            if (comparedStack.stackSize <= reqCounts.get(r)) {
              continue;
            }
            if (StackHelper.isMatchingItem(inputStack,comparedStack,true,false)) {
              requirements[i]=r;
              filteredReqsToFulfill--;
              reqCounts.adjustOrPutValue(r,1,1);
              break;
            }
          }
        }
      }
    }
  }
  Map<EnumFacing,IInventory> invs=new HashMap<EnumFacing,IInventory>();
  if (filteredReqsToFulfill > 0 || missingCount > 0) {
    for (int i=2; i < 6; i++) {
      TileEntity neighbor=getTile(EnumFacing.getOrientation(i));
      if (neighbor instanceof IInventory) {
        invs.put(EnumFacing.getOrientation(i),(IInventory)neighbor);
      }
    }
  }
  if (filteredReqsToFulfill > 0) {
    for (    EnumFacing dir : invs.keySet()) {
      if (filteredReqsToFulfill == 0) {
        break;
      }
      IInventory inv=invs.get(dir);
      Iterable<IInvSlot> iterator=InventoryIterator.getIterable(inv,dir);
      for (      IInvSlot slot : iterator) {
        if (filteredReqsToFulfill == 0) {
          break;
        }
        ItemStack comparedStack=slot.getStackInSlot();
        if (comparedStack == null || !slot.canTakeStackFromSlot(comparedStack)) {
          continue;
        }
        Requirement r=new Requirement(inv,slot.getIndex());
        if (comparedStack.stackSize <= reqCounts.get(r)) {
          continue;
        }
        for (int j=0; j < 9; j++) {
          ItemStack inputStack=inventoryPattern.getStackInSlot(j);
          if (isPatternSlotSet(j) && requirements[j] == null && inputStack != null) {
            if (StackHelper.isMatchingItem(inputStack,comparedStack,true,false)) {
              filteredReqsToFulfill--;
              requirements[j]=r;
              reqCounts.adjustOrPutValue(r,1,1);
              break;
            }
          }
        }
      }
    }
  }
  if (filteredReqsToFulfill > 0) {
    return false;
  }
  boolean foundMissing=false;
  if (missingCount > 0) {
    for (int i=0; i < 9; i++) {
      Requirement r=new Requirement(this,i);
      if (reqCounts.contains(r)) {
        continue;
      }
      if (validMissing(r,missingCount)) {
        foundMissing=true;
        for (int j=0; j < 9; j++) {
          if (requirements[j] == null && isPatternSlotSet(j) && inventoryPattern.getStackInSlot(j) == null) {
            requirements[j]=r;
          }
        }
        reqCounts.adjustOrPutValue(r,missingCount,missingCount);
        missingCount=0;
        break;
      }
    }
  }
  if (missingCount > 0) {
    for (    EnumFacing dir : invs.keySet()) {
      if (foundMissing) {
        break;
      }
      IInventory inv=invs.get(dir);
      Iterable<IInvSlot> iterator=InventoryIterator.getIterable(inv,dir);
      for (      IInvSlot slot : iterator) {
        if (foundMissing) {
          break;
        }
        Requirement r=new Requirement(inv,slot.getIndex());
        if (reqCounts.contains(r)) {
          continue;
        }
        if (validMissing(r,missingCount)) {
          foundMissing=true;
          for (int j=0; j < 9; j++) {
            if (requirements[j] == null && isPatternSlotSet(j) && inventoryPattern.getStackInSlot(j) == null) {
              requirements[j]=r;
            }
          }
          reqCounts.adjustOrPutValue(r,missingCount,missingCount);
          missingCount=0;
          break;
        }
      }
    }
  }
  if (missingCount > 0) {
    return false;
  }
  ItemStack pkg;
  if (input.getItem() instanceof ItemPackage) {
    pkg=input.copy();
  }
 else {
    pkg=new ItemStack(BuildCraftSilicon.packageItem);
  }
  NBTTagCompound pkgTag=NBTUtils.getItemData(pkg);
  boolean broken=false;
  for (int i=0; i < 9; i++) {
    if (isPatternSlotSet(i)) {
      if (requirements[i] == null) {
        BCLog.logger.error("String_Node_Str" + xCoord + "String_Node_Str"+ yCoord+ "String_Node_Str"+ zCoord+ "String_Node_Str"+ i+ "String_Node_Str");
        broken=true;
        continue;
      }
      ItemStack usedStack=requirements[i].decrStackSize(1);
      if (usedStack == null) {
        BCLog.logger.error("String_Node_Str" + xCoord + "String_Node_Str"+ yCoord+ "String_Node_Str"+ zCoord+ "String_Node_Str"+ i+ "String_Node_Str");
        broken=true;
        continue;
      }
      NBTTagCompound itemTag=new NBTTagCompound();
      usedStack.writeToNBT(itemTag);
      pkgTag.setTag("String_Node_Str" + i,itemTag);
    }
  }
  if (broken) {
    return false;
  }
  ItemPackage.update(pkg);
  decrStackSize(9,1);
  setInventorySlotContents(11,pkg);
  return true;
}

Fixed version (ground truth):
private boolean attemptCrafting(ItemStack input){
  if (inventoryPublic.getStackInSlot(11) != null) {
    return false;
  }
  if (input == null || input.stackSize == 0 || !(input.getItem() == Items.paper || input.getItem() instanceof ItemPackage)) {
    return false;
  }
  if (input.getItem() instanceof ItemPackage) {
    NBTTagCompound inputTag=NBTUtils.getItemData(input);
    for (int i=0; i < 9; i++) {
      if (isPatternSlotSet(i) && inputTag.hasKey("String_Node_Str" + i)) {
        return false;
      }
    }
  }
  TObjectIntHashMap<Requirement> reqCounts=new TObjectIntHashMap<Requirement>(9);
  int missingCount=0;
  int filteredReqsToFulfill=0;
  for (int i=0; i < 9; i++) {
    if (isPatternSlotSet(i)) {
      ItemStack inputStack=inventoryPattern.getStackInSlot(i);
      if (inputStack != null) {
        filteredReqsToFulfill++;
      }
 else {
        missingCount++;
        requirements[i]=null;
        continue;
      }
      Requirement r=requirements[i];
      if (r == null) {
        continue;
      }
      if (!r.isValid()) {
        requirements[i]=null;
        continue;
      }
      if (r.getStack() == null) {
        requirements[i]=null;
        continue;
      }
      if (inputStack != null) {
        if (!StackHelper.isMatchingItem(inputStack,r.getStack(),true,false)) {
          requirements[i]=null;
          continue;
        }
      }
      reqCounts.adjustOrPutValue(requirements[i],1,1);
      filteredReqsToFulfill--;
    }
 else {
      requirements[i]=null;
    }
  }
  for (  Requirement r : reqCounts.keys(new Requirement[reqCounts.size()])) {
    if (r.getStack().stackSize < reqCounts.get(r)) {
      int allowedAmount=0;
      for (int i=0; i < 9; i++) {
        if (requirements[i] != null && requirements[i].equals(r)) {
          allowedAmount--;
          if (allowedAmount < 0) {
            requirements[i]=null;
            filteredReqsToFulfill++;
          }
        }
      }
      reqCounts.remove(r);
    }
  }
  if (filteredReqsToFulfill > 0) {
    for (int i=0; i < 9; i++) {
      if (filteredReqsToFulfill == 0) {
        break;
      }
      if (isPatternSlotSet(i) && requirements[i] == null) {
        ItemStack inputStack=inventoryPattern.getStackInSlot(i);
        if (inputStack != null) {
          for (int j=0; j < 9; j++) {
            ItemStack comparedStack=inventoryPublic.getStackInSlot(j);
            if (comparedStack == null) {
              continue;
            }
            Requirement r=new Requirement(this,j);
            if (comparedStack.stackSize <= reqCounts.get(r)) {
              continue;
            }
            if (StackHelper.isMatchingItem(inputStack,comparedStack,true,false)) {
              requirements[i]=r;
              filteredReqsToFulfill--;
              reqCounts.adjustOrPutValue(r,1,1);
              break;
            }
          }
        }
      }
    }
  }
  Map<EnumFacing,IInventory> invs=new HashMap<EnumFacing,IInventory>();
  if (filteredReqsToFulfill > 0 || missingCount > 0) {
    for (int i=2; i < 6; i++) {
      TileEntity neighbor=getTile(EnumFacing.getFront(i));
      if (neighbor instanceof IInventory) {
        invs.put(EnumFacing.getFront(i),(IInventory)neighbor);
      }
    }
  }
  if (filteredReqsToFulfill > 0) {
    for (    EnumFacing dir : invs.keySet()) {
      if (filteredReqsToFulfill == 0) {
        break;
      }
      IInventory inv=invs.get(dir);
      Iterable<IInvSlot> iterator=InventoryIterator.getIterable(inv,dir);
      for (      IInvSlot slot : iterator) {
        if (filteredReqsToFulfill == 0) {
          break;
        }
        ItemStack comparedStack=slot.getStackInSlot();
        if (comparedStack == null || !slot.canTakeStackFromSlot(comparedStack)) {
          continue;
        }
        Requirement r=new Requirement(inv,slot.getIndex());
        if (comparedStack.stackSize <= reqCounts.get(r)) {
          continue;
        }
        for (int j=0; j < 9; j++) {
          ItemStack inputStack=inventoryPattern.getStackInSlot(j);
          if (isPatternSlotSet(j) && requirements[j] == null && inputStack != null) {
            if (StackHelper.isMatchingItem(inputStack,comparedStack,true,false)) {
              filteredReqsToFulfill--;
              requirements[j]=r;
              reqCounts.adjustOrPutValue(r,1,1);
              break;
            }
          }
        }
      }
    }
  }
  if (filteredReqsToFulfill > 0) {
    return false;
  }
  boolean foundMissing=false;
  if (missingCount > 0) {
    for (int i=0; i < 9; i++) {
      Requirement r=new Requirement(this,i);
      if (reqCounts.contains(r)) {
        continue;
      }
      if (validMissing(r,missingCount)) {
        foundMissing=true;
        for (int j=0; j < 9; j++) {
          if (requirements[j] == null && isPatternSlotSet(j) && inventoryPattern.getStackInSlot(j) == null) {
            requirements[j]=r;
          }
        }
        reqCounts.adjustOrPutValue(r,missingCount,missingCount);
        missingCount=0;
        break;
      }
    }
  }
  if (missingCount > 0) {
    for (    EnumFacing dir : invs.keySet()) {
      if (foundMissing) {
        break;
      }
      IInventory inv=invs.get(dir);
      Iterable<IInvSlot> iterator=InventoryIterator.getIterable(inv,dir);
      for (      IInvSlot slot : iterator) {
        if (foundMissing) {
          break;
        }
        Requirement r=new Requirement(inv,slot.getIndex());
        if (reqCounts.contains(r)) {
          continue;
        }
        if (validMissing(r,missingCount)) {
          foundMissing=true;
          for (int j=0; j < 9; j++) {
            if (requirements[j] == null && isPatternSlotSet(j) && inventoryPattern.getStackInSlot(j) == null) {
              requirements[j]=r;
            }
          }
          reqCounts.adjustOrPutValue(r,missingCount,missingCount);
          missingCount=0;
          break;
        }
      }
    }
  }
  if (missingCount > 0) {
    return false;
  }
  ItemStack pkg;
  if (input.getItem() instanceof ItemPackage) {
    pkg=input.copy();
  }
 else {
    pkg=new ItemStack(BuildCraftSilicon.packageItem);
  }
  NBTTagCompound pkgTag=NBTUtils.getItemData(pkg);
  boolean broken=false;
  for (int i=0; i < 9; i++) {
    if (isPatternSlotSet(i)) {
      if (requirements[i] == null) {
        BCLog.logger.error("String_Node_Str" + xCoord + "String_Node_Str"+ yCoord+ "String_Node_Str"+ zCoord+ "String_Node_Str"+ i+ "String_Node_Str");
        broken=true;
        continue;
      }
      ItemStack usedStack=requirements[i].decrStackSize(1);
      if (usedStack == null) {
        BCLog.logger.error("String_Node_Str" + xCoord + "String_Node_Str"+ yCoord+ "String_Node_Str"+ zCoord+ "String_Node_Str"+ i+ "String_Node_Str");
        broken=true;
        continue;
      }
      NBTTagCompound itemTag=new NBTTagCompound();
      usedStack.writeToNBT(itemTag);
      pkgTag.setTag("String_Node_Str" + i,itemTag);
    }
  }
  if (broken) {
    return false;
  }
  ItemPackage.update(pkg);
  decrStackSize(9,1);
  setInventorySlotContents(11,pkg);
  return true;
}