Program: 85783
Project: 85783
Buggy source:
@Override protected synchronized TransactionOutputChanges connectTransactions(StoredBlock newBlock) throws VerificationException, BlockStoreException, PrunedException {
  checkState(lock.isHeldByCurrentThread());
  if (!params.passesCheckpoint(newBlock.getHeight(),newBlock.getHeader().getHash()))   throw new VerificationException("String_Node_Str" + newBlock.getHeight());
  blockStore.beginDatabaseBatchWrite();
  StoredUndoableBlock block=blockStore.getUndoBlock(newBlock.getHeader().getHash());
  if (block == null) {
    blockStore.abortDatabaseBatchWrite();
    throw new PrunedException(newBlock.getHeader().getHash());
  }
  TransactionOutputChanges txOutChanges;
  try {
    List<Transaction> transactions=block.getTransactions();
    if (transactions != null) {
      LinkedList<StoredTransactionOutput> txOutsSpent=new LinkedList<StoredTransactionOutput>();
      LinkedList<StoredTransactionOutput> txOutsCreated=new LinkedList<StoredTransactionOutput>();
      long sigOps=0;
      final boolean enforcePayToScriptHash=newBlock.getHeader().getTimeSeconds() >= NetworkParameters.BIP16_ENFORCE_TIME;
      if (!params.isCheckpoint(newBlock.getHeight())) {
        for (        Transaction tx : transactions) {
          Sha256Hash hash=tx.getHash();
          if (blockStore.hasUnspentOutputs(hash,tx.getOutputs().size()))           throw new VerificationException("String_Node_Str");
        }
      }
      BigInteger totalFees=BigInteger.ZERO;
      BigInteger coinbaseValue=null;
      if (scriptVerificationExecutor.isShutdown())       scriptVerificationExecutor=Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
      List<Future<VerificationException>> listScriptVerificationResults=new ArrayList<Future<VerificationException>>(transactions.size());
      for (      final Transaction tx : transactions) {
        boolean isCoinBase=tx.isCoinBase();
        BigInteger valueIn=BigInteger.ZERO;
        BigInteger valueOut=BigInteger.ZERO;
        final List<Script> prevOutScripts=new LinkedList<Script>();
        if (!isCoinBase) {
          for (int index=0; index < tx.getInputs().size(); index++) {
            final TransactionInput in=tx.getInputs().get(index);
            final StoredTransactionOutput prevOut=blockStore.getTransactionOutput(in.getOutpoint().getHash(),in.getOutpoint().getIndex());
            if (prevOut == null)             throw new VerificationException("String_Node_Str");
            if (newBlock.getHeight() - prevOut.getHeight() < params.getSpendableCoinbaseDepth())             throw new VerificationException("String_Node_Str" + (newBlock.getHeight() - prevOut.getHeight()));
            valueIn=valueIn.add(prevOut.getValue());
            if (enforcePayToScriptHash) {
              Script script=new Script(prevOut.getScriptBytes());
              if (script.isPayToScriptHash())               sigOps+=Script.getP2SHSigOpCount(in.getScriptBytes());
              if (sigOps > Block.MAX_BLOCK_SIGOPS)               throw new VerificationException("String_Node_Str");
            }
            prevOutScripts.add(new Script(prevOut.getScriptBytes()));
            blockStore.removeUnspentTransactionOutput(prevOut);
            txOutsSpent.add(prevOut);
          }
        }
        Sha256Hash hash=tx.getHash();
        for (        TransactionOutput out : tx.getOutputs()) {
          valueOut=valueOut.add(out.getValue());
          StoredTransactionOutput newOut=new StoredTransactionOutput(hash,out.getIndex(),out.getValue(),newBlock.getHeight(),isCoinBase,out.getScriptBytes());
          blockStore.addUnspentTransactionOutput(newOut);
          txOutsCreated.add(newOut);
        }
        if (valueOut.compareTo(BigInteger.ZERO) < 0 || valueOut.compareTo(params.MAX_MONEY) > 0)         throw new VerificationException("String_Node_Str");
        if (isCoinBase) {
          coinbaseValue=valueOut;
        }
 else {
          if (valueIn.compareTo(valueOut) < 0 || valueIn.compareTo(params.MAX_MONEY) > 0)           throw new VerificationException("String_Node_Str");
          totalFees=totalFees.add(valueIn.subtract(valueOut));
        }
        if (!isCoinBase) {
          FutureTask<VerificationException> future=new FutureTask<VerificationException>(new Verifyer(tx,prevOutScripts,enforcePayToScriptHash));
          scriptVerificationExecutor.execute(future);
          listScriptVerificationResults.add(future);
        }
      }
      if (totalFees.compareTo(params.MAX_MONEY) > 0 || newBlock.getHeader().getBlockInflation(newBlock.getHeight()).add(totalFees).compareTo(coinbaseValue) < 0)       throw new VerificationException("String_Node_Str");
      txOutChanges=new TransactionOutputChanges(txOutsCreated,txOutsSpent);
      for (      Future<VerificationException> future : listScriptVerificationResults) {
        VerificationException e;
        try {
          e=future.get();
        }
 catch (        InterruptedException thrownE) {
          throw new RuntimeException(thrownE);
        }
catch (        ExecutionException thrownE) {
          log.error("String_Node_Str" + thrownE.getCause());
          throw new VerificationException("String_Node_Str",thrownE);
        }
        if (e != null)         throw e;
      }
    }
 else {
      txOutChanges=block.getTxOutChanges();
      if (!params.isCheckpoint(newBlock.getHeight()))       for (      StoredTransactionOutput out : txOutChanges.txOutsCreated) {
        Sha256Hash hash=out.getHash();
        if (blockStore.getTransactionOutput(hash,out.getIndex()) != null)         throw new VerificationException("String_Node_Str");
      }
      for (      StoredTransactionOutput out : txOutChanges.txOutsCreated)       blockStore.addUnspentTransactionOutput(out);
      for (      StoredTransactionOutput out : txOutChanges.txOutsSpent)       blockStore.removeUnspentTransactionOutput(out);
    }
  }
 catch (  VerificationException e) {
    scriptVerificationExecutor.shutdownNow();
    blockStore.abortDatabaseBatchWrite();
    throw e;
  }
catch (  BlockStoreException e) {
    scriptVerificationExecutor.shutdownNow();
    blockStore.abortDatabaseBatchWrite();
    throw e;
  }
  return txOutChanges;
}

Fixed version (ground truth):
@Override protected synchronized TransactionOutputChanges connectTransactions(StoredBlock newBlock) throws VerificationException, BlockStoreException, PrunedException {
  checkState(lock.isHeldByCurrentThread());
  if (!params.passesCheckpoint(newBlock.getHeight(),newBlock.getHeader().getHash()))   throw new VerificationException("String_Node_Str" + newBlock.getHeight());
  blockStore.beginDatabaseBatchWrite();
  StoredUndoableBlock block=blockStore.getUndoBlock(newBlock.getHeader().getHash());
  if (block == null) {
    blockStore.abortDatabaseBatchWrite();
    throw new PrunedException(newBlock.getHeader().getHash());
  }
  TransactionOutputChanges txOutChanges;
  try {
    List<Transaction> transactions=block.getTransactions();
    if (transactions != null) {
      LinkedList<StoredTransactionOutput> txOutsSpent=new LinkedList<StoredTransactionOutput>();
      LinkedList<StoredTransactionOutput> txOutsCreated=new LinkedList<StoredTransactionOutput>();
      long sigOps=0;
      final boolean enforcePayToScriptHash=newBlock.getHeader().getTimeSeconds() >= NetworkParameters.BIP16_ENFORCE_TIME;
      if (!params.isCheckpoint(newBlock.getHeight())) {
        for (        Transaction tx : transactions) {
          Sha256Hash hash=tx.getHash();
          if (blockStore.hasUnspentOutputs(hash,tx.getOutputs().size()))           throw new VerificationException("String_Node_Str");
        }
      }
      BigInteger totalFees=BigInteger.ZERO;
      BigInteger coinbaseValue=null;
      if (scriptVerificationExecutor.isShutdown())       scriptVerificationExecutor=Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
      List<Future<VerificationException>> listScriptVerificationResults=new ArrayList<Future<VerificationException>>(transactions.size());
      for (      final Transaction tx : transactions) {
        boolean isCoinBase=tx.isCoinBase();
        BigInteger valueIn=BigInteger.ZERO;
        BigInteger valueOut=BigInteger.ZERO;
        final List<Script> prevOutScripts=new LinkedList<Script>();
        if (!isCoinBase) {
          for (int index=0; index < tx.getInputs().size(); index++) {
            final TransactionInput in=tx.getInputs().get(index);
            final StoredTransactionOutput prevOut=blockStore.getTransactionOutput(in.getOutpoint().getHash(),in.getOutpoint().getIndex());
            if (prevOut == null)             throw new VerificationException("String_Node_Str");
            if (newBlock.getHeight() - prevOut.getHeight() < params.getSpendableCoinbaseDepth())             throw new VerificationException("String_Node_Str" + (newBlock.getHeight() - prevOut.getHeight()));
            valueIn=valueIn.add(prevOut.getValue());
            if (enforcePayToScriptHash) {
              Script script=new Script(prevOut.getScriptBytes());
              if (script.isPayToScriptHash())               sigOps+=Script.getP2SHSigOpCount(in.getScriptBytes());
              if (sigOps > Block.MAX_BLOCK_SIGOPS)               throw new VerificationException("String_Node_Str");
            }
            prevOutScripts.add(new Script(prevOut.getScriptBytes()));
            blockStore.removeUnspentTransactionOutput(prevOut);
            txOutsSpent.add(prevOut);
          }
        }
        Sha256Hash hash=tx.getHash();
        for (        TransactionOutput out : tx.getOutputs()) {
          valueOut=valueOut.add(out.getValue());
          StoredTransactionOutput newOut=new StoredTransactionOutput(hash,out.getIndex(),out.getValue(),newBlock.getHeight(),isCoinBase,out.getScriptBytes());
          blockStore.addUnspentTransactionOutput(newOut);
          txOutsCreated.add(newOut);
        }
        if (valueOut.compareTo(BigInteger.ZERO) < 0 || valueOut.compareTo(params.MAX_MONEY) > 0)         throw new VerificationException("String_Node_Str");
        if (isCoinBase) {
          coinbaseValue=valueOut;
        }
 else {
          if (valueIn.compareTo(valueOut) < 0 || valueIn.compareTo(params.MAX_MONEY) > 0)           throw new VerificationException("String_Node_Str");
          totalFees=totalFees.add(valueIn.subtract(valueOut));
        }
        if (!isCoinBase) {
          FutureTask<VerificationException> future=new FutureTask<VerificationException>(new Verifier(tx,prevOutScripts,enforcePayToScriptHash));
          scriptVerificationExecutor.execute(future);
          listScriptVerificationResults.add(future);
        }
      }
      if (totalFees.compareTo(params.MAX_MONEY) > 0 || newBlock.getHeader().getBlockInflation(newBlock.getHeight()).add(totalFees).compareTo(coinbaseValue) < 0)       throw new VerificationException("String_Node_Str");
      txOutChanges=new TransactionOutputChanges(txOutsCreated,txOutsSpent);
      for (      Future<VerificationException> future : listScriptVerificationResults) {
        VerificationException e;
        try {
          e=future.get();
        }
 catch (        InterruptedException thrownE) {
          throw new RuntimeException(thrownE);
        }
catch (        ExecutionException thrownE) {
          log.error("String_Node_Str" + thrownE.getCause());
          throw new VerificationException("String_Node_Str",thrownE);
        }
        if (e != null)         throw e;
      }
    }
 else {
      txOutChanges=block.getTxOutChanges();
      if (!params.isCheckpoint(newBlock.getHeight()))       for (      StoredTransactionOutput out : txOutChanges.txOutsCreated) {
        Sha256Hash hash=out.getHash();
        if (blockStore.getTransactionOutput(hash,out.getIndex()) != null)         throw new VerificationException("String_Node_Str");
      }
      for (      StoredTransactionOutput out : txOutChanges.txOutsCreated)       blockStore.addUnspentTransactionOutput(out);
      for (      StoredTransactionOutput out : txOutChanges.txOutsSpent)       blockStore.removeUnspentTransactionOutput(out);
    }
  }
 catch (  VerificationException e) {
    scriptVerificationExecutor.shutdownNow();
    blockStore.abortDatabaseBatchWrite();
    throw e;
  }
catch (  BlockStoreException e) {
    scriptVerificationExecutor.shutdownNow();
    blockStore.abortDatabaseBatchWrite();
    throw e;
  }
  return txOutChanges;
}