Program: 85944
Project: 85944
Buggy source:
/** 
 * Called by the   {@link BlockChain} when the best chain (representing total work done) has changed. In this case,we need to go through our transactions and find out if any have become invalid. It's possible for our balance to go down in this case: money we thought we had can suddenly vanish if the rest of the network agrees it should be so.<p> The oldBlocks/newBlocks lists are ordered height-wise from top first to bottom last.
 */
synchronized void reorganize(List<StoredBlock> oldBlocks,List<StoredBlock> newBlocks) throws VerificationException {
  List<Sha256Hash> oldBlockHashes=new ArrayList<Sha256Hash>(oldBlocks.size());
  List<Sha256Hash> newBlockHashes=new ArrayList<Sha256Hash>(newBlocks.size());
  log.info("String_Node_Str");
  for (  StoredBlock b : oldBlocks) {
    log.info("String_Node_Str",b.getHeader().getHashAsString());
    oldBlockHashes.add(b.getHeader().getHash());
  }
  log.info("String_Node_Str");
  for (  StoredBlock b : newBlocks) {
    log.info("String_Node_Str",b.getHeader().getHashAsString());
    newBlockHashes.add(b.getHeader().getHash());
  }
  Map<Sha256Hash,Transaction> oldChainTransactions=new HashMap<Sha256Hash,Transaction>();
  Map<Sha256Hash,Transaction> onlyOldChainTransactions=new HashMap<Sha256Hash,Transaction>();
  Map<Sha256Hash,Transaction> newChainTransactions=new HashMap<Sha256Hash,Transaction>();
  Map<Sha256Hash,Transaction> commonChainTransactions=new HashMap<Sha256Hash,Transaction>();
  Map<Sha256Hash,Transaction> all=new HashMap<Sha256Hash,Transaction>();
  all.putAll(unspent);
  all.putAll(spent);
  all.putAll(inactive);
  for (  Transaction tx : all.values()) {
    Collection<Sha256Hash> appearsIn=tx.getAppearsInHashes();
    checkNotNull(appearsIn);
    boolean inOldSection=!Collections.disjoint(appearsIn,oldBlockHashes);
    boolean inNewSection=!Collections.disjoint(appearsIn,newBlockHashes);
    boolean inCommonSection=!inNewSection && !inOldSection;
    if (inCommonSection) {
      boolean alreadyPresent=commonChainTransactions.put(tx.getHash(),tx) != null;
      checkState(!alreadyPresent,"String_Node_Str");
    }
 else {
      if (inOldSection) {
        boolean alreadyPresent=oldChainTransactions.put(tx.getHash(),tx) != null;
        checkState(!alreadyPresent,"String_Node_Str");
        if (!inNewSection) {
          alreadyPresent=onlyOldChainTransactions.put(tx.getHash(),tx) != null;
          checkState(!alreadyPresent,"String_Node_Str");
        }
      }
      if (inNewSection) {
        boolean alreadyPresent=newChainTransactions.put(tx.getHash(),tx) != null;
        checkState(!alreadyPresent,"String_Node_Str");
      }
    }
  }
  boolean affectedUs=!oldChainTransactions.equals(newChainTransactions);
  log.info(affectedUs ? "String_Node_Str" : "String_Node_Str");
  if (!affectedUs)   return;
  for (  Transaction tx : onlyOldChainTransactions.values())   log.info("String_Node_Str",tx.getHashAsString());
  for (  Transaction tx : oldChainTransactions.values())   log.info("String_Node_Str",tx.getHashAsString());
  for (  Transaction tx : newChainTransactions.values())   log.info("String_Node_Str",tx.getHashAsString());
  for (  Transaction tx : all.values())   tx.disconnectInputs();
  for (  Transaction tx : pending.values())   tx.disconnectInputs();
  for (  Transaction tx : commonChainTransactions.values()) {
    TransactionInput badInput=tx.connectForReorganize(all);
    checkState(badInput == null,"String_Node_Str",tx.getHashAsString(),badInput == null ? "String_Node_Str" : badInput.toString());
  }
  log.info("String_Node_Str");
  unspent.clear();
  spent.clear();
  inactive.clear();
  for (  Transaction tx : commonChainTransactions.values()) {
    int unspentOutputs=0;
    for (    TransactionOutput output : tx.getOutputs()) {
      if (output.isAvailableForSpending())       unspentOutputs++;
    }
    if (unspentOutputs > 0) {
      log.info("String_Node_Str",tx.getHashAsString());
      unspent.put(tx.getHash(),tx);
    }
 else {
      log.info("String_Node_Str",tx.getHashAsString());
      spent.put(tx.getHash(),tx);
    }
  }
  for (  Transaction tx : onlyOldChainTransactions.values()) {
    tx.notifyNotOnBestChain();
  }
  Collections.reverse(newBlocks);
  for (  StoredBlock b : newBlocks) {
    log.info("String_Node_Str",b.getHeader().getHashAsString());
    Set<Transaction> txns=new HashSet<Transaction>();
    Sha256Hash blockHash=b.getHeader().getHash();
    for (    Transaction tx : newChainTransactions.values()) {
      if (tx.getAppearsInHashes().contains(blockHash)) {
        txns.add(tx);
        log.info("String_Node_Str",tx.getHashAsString());
      }
    }
    for (    Transaction t : txns) {
      try {
        receive(t,b,BlockChain.NewBlockType.BEST_CHAIN,true);
      }
 catch (      ScriptException e) {
        throw new RuntimeException(e);
      }
    }
  }
  Map<Sha256Hash,Transaction> pool=new HashMap<Sha256Hash,Transaction>();
  pool.putAll(unspent);
  pool.putAll(spent);
  pool.putAll(pending);
  Map<Sha256Hash,Transaction> toReprocess=new HashMap<Sha256Hash,Transaction>();
  toReprocess.putAll(onlyOldChainTransactions);
  toReprocess.putAll(pending);
  log.info("String_Node_Str");
  for (  Transaction tx : dead.values()) {
    reprocessTxAfterReorg(pool,tx);
  }
  for (  Transaction tx : toReprocess.values()) {
    reprocessTxAfterReorg(pool,tx);
  }
  log.info("String_Node_Str",Utils.bitcoinValueToFriendlyString(getBalance()));
  EventListenerInvoker.invoke(eventListeners,new EventListenerInvoker<WalletEventListener>(){
    @Override public void invoke(    WalletEventListener listener){
      listener.onReorganize(Wallet.this);
    }
  }
);
  checkState(isConsistent());
}

Fixed version (ground truth):
/** 
 * Called by the   {@link BlockChain} when the best chain (representing total work done) has changed. In this case,we need to go through our transactions and find out if any have become invalid. It's possible for our balance to go down in this case: money we thought we had can suddenly vanish if the rest of the network agrees it should be so.<p> The oldBlocks/newBlocks lists are ordered height-wise from top first to bottom last.
 */
synchronized void reorganize(List<StoredBlock> oldBlocks,List<StoredBlock> newBlocks) throws VerificationException {
  List<Sha256Hash> oldBlockHashes=new ArrayList<Sha256Hash>(oldBlocks.size());
  List<Sha256Hash> newBlockHashes=new ArrayList<Sha256Hash>(newBlocks.size());
  log.info("String_Node_Str");
  for (  StoredBlock b : oldBlocks) {
    log.info("String_Node_Str",b.getHeader().getHashAsString());
    oldBlockHashes.add(b.getHeader().getHash());
  }
  log.info("String_Node_Str");
  for (  StoredBlock b : newBlocks) {
    log.info("String_Node_Str",b.getHeader().getHashAsString());
    newBlockHashes.add(b.getHeader().getHash());
  }
  Map<Sha256Hash,Transaction> oldChainTransactions=new HashMap<Sha256Hash,Transaction>();
  Map<Sha256Hash,Transaction> onlyOldChainTransactions=new HashMap<Sha256Hash,Transaction>();
  Map<Sha256Hash,Transaction> newChainTransactions=new HashMap<Sha256Hash,Transaction>();
  Map<Sha256Hash,Transaction> commonChainTransactions=new HashMap<Sha256Hash,Transaction>();
  Map<Sha256Hash,Transaction> all=new HashMap<Sha256Hash,Transaction>();
  all.putAll(unspent);
  all.putAll(spent);
  all.putAll(inactive);
  for (  Transaction tx : all.values()) {
    Collection<Sha256Hash> appearsIn=tx.getAppearsInHashes();
    checkNotNull(appearsIn);
    boolean inOldSection=!Collections.disjoint(appearsIn,oldBlockHashes);
    boolean inNewSection=!Collections.disjoint(appearsIn,newBlockHashes);
    boolean inCommonSection=!inNewSection && !inOldSection;
    if (inCommonSection) {
      boolean alreadyPresent=commonChainTransactions.put(tx.getHash(),tx) != null;
      checkState(!alreadyPresent,"String_Node_Str");
    }
 else {
      if (inOldSection) {
        boolean alreadyPresent=oldChainTransactions.put(tx.getHash(),tx) != null;
        checkState(!alreadyPresent,"String_Node_Str");
        if (!inNewSection) {
          alreadyPresent=onlyOldChainTransactions.put(tx.getHash(),tx) != null;
          checkState(!alreadyPresent,"String_Node_Str");
        }
      }
      if (inNewSection) {
        boolean alreadyPresent=newChainTransactions.put(tx.getHash(),tx) != null;
        checkState(!alreadyPresent,"String_Node_Str");
      }
    }
  }
  boolean affectedUs=!oldChainTransactions.equals(newChainTransactions);
  log.info(affectedUs ? "String_Node_Str" : "String_Node_Str");
  if (!affectedUs)   return;
  for (  Transaction tx : onlyOldChainTransactions.values())   log.info("String_Node_Str",tx.getHashAsString());
  for (  Transaction tx : oldChainTransactions.values())   log.info("String_Node_Str",tx.getHashAsString());
  for (  Transaction tx : newChainTransactions.values())   log.info("String_Node_Str",tx.getHashAsString());
  for (  Transaction tx : all.values())   tx.disconnectInputs();
  for (  Transaction tx : pending.values())   tx.disconnectInputs();
  for (  Transaction tx : commonChainTransactions.values()) {
    TransactionInput badInput=tx.connectForReorganize(all);
    checkState(badInput == null,"String_Node_Str",tx.getHashAsString(),badInput == null ? "String_Node_Str" : badInput.toString());
  }
  log.info("String_Node_Str");
  unspent.clear();
  spent.clear();
  inactive.clear();
  for (  Transaction tx : commonChainTransactions.values()) {
    int unspentOutputs=0;
    for (    TransactionOutput output : tx.getOutputs()) {
      if (output.isAvailableForSpending() && output.isMine(this))       unspentOutputs++;
    }
    if (unspentOutputs > 0) {
      log.info("String_Node_Str",tx.getHashAsString());
      unspent.put(tx.getHash(),tx);
    }
 else {
      log.info("String_Node_Str",tx.getHashAsString());
      spent.put(tx.getHash(),tx);
    }
  }
  for (  Transaction tx : onlyOldChainTransactions.values()) {
    tx.notifyNotOnBestChain();
  }
  Collections.reverse(newBlocks);
  for (  StoredBlock b : newBlocks) {
    log.info("String_Node_Str",b.getHeader().getHashAsString());
    Set<Transaction> txns=new HashSet<Transaction>();
    Sha256Hash blockHash=b.getHeader().getHash();
    for (    Transaction tx : newChainTransactions.values()) {
      if (tx.getAppearsInHashes().contains(blockHash)) {
        txns.add(tx);
        log.info("String_Node_Str",tx.getHashAsString());
      }
    }
    for (    Transaction t : txns) {
      try {
        receive(t,b,BlockChain.NewBlockType.BEST_CHAIN,true);
      }
 catch (      ScriptException e) {
        throw new RuntimeException(e);
      }
    }
  }
  Map<Sha256Hash,Transaction> pool=new HashMap<Sha256Hash,Transaction>();
  pool.putAll(unspent);
  pool.putAll(spent);
  pool.putAll(pending);
  Map<Sha256Hash,Transaction> toReprocess=new HashMap<Sha256Hash,Transaction>();
  toReprocess.putAll(onlyOldChainTransactions);
  toReprocess.putAll(pending);
  log.info("String_Node_Str");
  for (  Transaction tx : dead.values()) {
    reprocessUnincludedTxAfterReorg(pool,tx);
  }
  for (  Transaction tx : toReprocess.values()) {
    reprocessUnincludedTxAfterReorg(pool,tx);
  }
  log.info("String_Node_Str",Utils.bitcoinValueToFriendlyString(getBalance()));
  EventListenerInvoker.invoke(eventListeners,new EventListenerInvoker<WalletEventListener>(){
    @Override public void invoke(    WalletEventListener listener){
      listener.onReorganize(Wallet.this);
    }
  }
);
  checkState(isConsistent());
}