Program: 85761
Project: 85761
Buggy source:
/** 
 * Given a spend request containing an incomplete transaction, makes it valid by adding outputs and signed inputs according to the instructions in the request. The transaction in the request is modified by this method, as is the fee parameter.
 * @param req a SendRequest that contains the incomplete transaction and details for how to make it valid.
 * @throws IllegalArgumentException if you try and complete the same SendRequest twice.
 * @return whether or not the requested send is affordable.
 */
public boolean completeTx(SendRequest req){
  lock.lock();
  try {
    Preconditions.checkArgument(!req.completed,"String_Node_Str");
    BigInteger value=BigInteger.ZERO;
    for (    TransactionOutput output : req.tx.getOutputs()) {
      value=value.add(output.getValue());
    }
    BigInteger totalOutput=value;
    log.info("String_Node_Str",req.tx.getOutputs().size(),bitcoinValueToFriendlyString(value));
    BigInteger totalInput=BigInteger.ZERO;
    for (    TransactionInput input : req.tx.getInputs())     if (input.getConnectedOutput() != null)     totalInput=totalInput.add(input.getConnectedOutput().getValue());
 else     log.warn("String_Node_Str");
    value=value.subtract(totalInput);
    List<TransactionInput> originalInputs=new ArrayList<TransactionInput>(req.tx.getInputs());
    boolean needAtLeastReferenceFee=false;
    if (req.ensureMinRequiredFee && !req.emptyWallet) {
      for (      TransactionOutput output : req.tx.getOutputs())       if (output.getValue().compareTo(Utils.CENT) < 0) {
        if (output.getValue().compareTo(output.getMinNonDustValue()) < 0) {
          log.error("String_Node_Str");
          return false;
        }
        needAtLeastReferenceFee=true;
        break;
      }
    }
    LinkedList<TransactionOutput> candidates=calculateAllSpendCandidates(true);
    CoinSelection bestCoinSelection;
    TransactionOutput bestChangeOutput=null;
    if (!req.emptyWallet) {
      FeeCalculation feeCalculation;
      try {
        feeCalculation=new FeeCalculation(req,value,originalInputs,needAtLeastReferenceFee,candidates);
      }
 catch (      InsufficientMoneyException e) {
        return false;
      }
      bestCoinSelection=feeCalculation.bestCoinSelection;
      bestChangeOutput=feeCalculation.bestChangeOutput;
    }
 else {
      checkState(req.tx.getOutputs().size() == 1,"String_Node_Str");
      CoinSelector selector=req.coinSelector == null ? coinSelector : req.coinSelector;
      bestCoinSelection=selector.select(NetworkParameters.MAX_MONEY,candidates);
      req.tx.getOutput(0).setValue(bestCoinSelection.valueGathered);
    }
    for (    TransactionOutput output : bestCoinSelection.gathered)     req.tx.addInput(output);
    if (req.ensureMinRequiredFee && req.emptyWallet) {
      final BigInteger baseFee=req.fee == null ? BigInteger.ZERO : req.fee;
      final BigInteger feePerKb=req.feePerKb == null ? BigInteger.ZERO : req.feePerKb;
      Transaction tx=req.tx;
      if (!adjustOutputDownwardsForFee(tx,bestCoinSelection,baseFee,feePerKb))       return false;
    }
    totalInput=totalInput.add(bestCoinSelection.valueGathered);
    if (bestChangeOutput != null) {
      req.tx.addOutput(bestChangeOutput);
      totalOutput=totalOutput.add(bestChangeOutput.getValue());
      log.info("String_Node_Str",bitcoinValueToFriendlyString(bestChangeOutput.getValue()));
    }
    final BigInteger calculatedFee=totalInput.subtract(totalOutput);
    if (calculatedFee.compareTo(BigInteger.ZERO) > 0) {
      log.info("String_Node_Str",bitcoinValueToFriendlyString(calculatedFee));
    }
    try {
      req.tx.signInputs(Transaction.SigHash.ALL,this,req.aesKey);
    }
 catch (    ScriptException e) {
      throw new RuntimeException(e);
    }
    int size=req.tx.bitcoinSerialize().length;
    if (size > Transaction.MAX_STANDARD_TX_SIZE) {
      log.warn(String.format("String_Node_Str",size,Transaction.MAX_STANDARD_TX_SIZE));
      return false;
    }
    req.tx.getConfidence().setSource(TransactionConfidence.Source.SELF);
    req.tx.setPurpose(Transaction.Purpose.USER_PAYMENT);
    req.completed=true;
    req.fee=calculatedFee;
    log.info("String_Node_Str",req.tx);
    return true;
  }
  finally {
    lock.unlock();
  }
}

Fixed version (ground truth):
/** 
 * Given a spend request containing an incomplete transaction, makes it valid by adding outputs and signed inputs according to the instructions in the request. The transaction in the request is modified by this method, as is the fee parameter.
 * @param req a SendRequest that contains the incomplete transaction and details for how to make it valid.
 * @throws IllegalArgumentException if you try and complete the same SendRequest twice.
 * @return whether or not the requested send is affordable.
 */
public boolean completeTx(SendRequest req){
  lock.lock();
  try {
    Preconditions.checkArgument(!req.completed,"String_Node_Str");
    BigInteger value=BigInteger.ZERO;
    for (    TransactionOutput output : req.tx.getOutputs()) {
      value=value.add(output.getValue());
    }
    BigInteger totalOutput=value;
    log.info("String_Node_Str",req.tx.getOutputs().size(),value);
    BigInteger totalInput=BigInteger.ZERO;
    for (    TransactionInput input : req.tx.getInputs())     if (input.getConnectedOutput() != null)     totalInput=totalInput.add(input.getConnectedOutput().getValue());
 else     log.warn("String_Node_Str");
    value=value.subtract(totalInput);
    List<TransactionInput> originalInputs=new ArrayList<TransactionInput>(req.tx.getInputs());
    boolean needAtLeastReferenceFee=false;
    if (req.ensureMinRequiredFee && !req.emptyWallet) {
      for (      TransactionOutput output : req.tx.getOutputs())       if (output.getValue().compareTo(Utils.CENT) < 0) {
        if (output.getValue().compareTo(output.getMinNonDustValue()) < 0) {
          log.error("String_Node_Str");
          return false;
        }
        needAtLeastReferenceFee=true;
        break;
      }
    }
    LinkedList<TransactionOutput> candidates=calculateAllSpendCandidates(true);
    CoinSelection bestCoinSelection;
    TransactionOutput bestChangeOutput=null;
    if (!req.emptyWallet) {
      FeeCalculation feeCalculation;
      try {
        feeCalculation=new FeeCalculation(req,value,originalInputs,needAtLeastReferenceFee,candidates);
      }
 catch (      InsufficientMoneyException e) {
        log.error("String_Node_Str");
        return false;
      }
      bestCoinSelection=feeCalculation.bestCoinSelection;
      bestChangeOutput=feeCalculation.bestChangeOutput;
    }
 else {
      checkState(req.tx.getOutputs().size() == 1,"String_Node_Str");
      CoinSelector selector=req.coinSelector == null ? coinSelector : req.coinSelector;
      bestCoinSelection=selector.select(NetworkParameters.MAX_MONEY,candidates);
      req.tx.getOutput(0).setValue(bestCoinSelection.valueGathered);
      totalOutput=bestCoinSelection.valueGathered;
    }
    for (    TransactionOutput output : bestCoinSelection.gathered)     req.tx.addInput(output);
    if (req.ensureMinRequiredFee && req.emptyWallet) {
      final BigInteger baseFee=req.fee == null ? BigInteger.ZERO : req.fee;
      final BigInteger feePerKb=req.feePerKb == null ? BigInteger.ZERO : req.feePerKb;
      Transaction tx=req.tx;
      if (!adjustOutputDownwardsForFee(tx,bestCoinSelection,baseFee,feePerKb)) {
        log.error("String_Node_Str");
        return false;
      }
    }
    totalInput=totalInput.add(bestCoinSelection.valueGathered);
    if (bestChangeOutput != null) {
      req.tx.addOutput(bestChangeOutput);
      totalOutput=totalOutput.add(bestChangeOutput.getValue());
      log.info("String_Node_Str",bitcoinValueToFriendlyString(bestChangeOutput.getValue()));
    }
    final BigInteger calculatedFee=totalInput.subtract(totalOutput);
    if (calculatedFee.compareTo(BigInteger.ZERO) > 0) {
      log.info("String_Node_Str",bitcoinValueToFriendlyString(calculatedFee));
    }
    try {
      req.tx.signInputs(Transaction.SigHash.ALL,this,req.aesKey);
    }
 catch (    ScriptException e) {
      throw new RuntimeException(e);
    }
    int size=req.tx.bitcoinSerialize().length;
    if (size > Transaction.MAX_STANDARD_TX_SIZE) {
      log.error("String_Node_Str",size,Transaction.MAX_STANDARD_TX_SIZE);
      return false;
    }
    req.tx.getConfidence().setSource(TransactionConfidence.Source.SELF);
    req.tx.setPurpose(Transaction.Purpose.USER_PAYMENT);
    req.completed=true;
    req.fee=calculatedFee;
    log.info("String_Node_Str",req.tx);
    return true;
  }
  finally {
    lock.unlock();
  }
}