[Demonstration 1]

[Buggy Method]
@Test
public void replayWhilstPending() throws Exception {
    // Check that if a pending transaction spends outputs of chain-included transactions, we mark them as spent.
    // See bug 345. This can happen if there is a pending transaction floating around and then you replay the
    // chain without emptying the memory pool (or refilling it from a peer).
    Coin value = COIN;
    Transaction tx1 = createFakeTx(params, value, myAddress);
    Transaction tx2 = new Transaction(params);
    tx2.addInput(tx1.getOutput(0));
    tx2.addOutput(valueOf(0, 9), new ECKey());
    // Add a change address to ensure this tx is relevant.
    tx2.addOutput(CENT, wallet.getChangeAddress());
    wallet.receivePending(tx2, null);
    BlockPair bp = createFakeBlock(blockStore, tx1);
    wallet.receiveFromBlock(tx1, bp.storedBlock, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
    wallet.notifyNewBestBlock(bp.storedBlock);
    assertEquals(ZERO, wallet.getBalance());
    assertEquals(1, wallet.getPoolSize(Pool.SPENT));
    assertEquals(1, wallet.getPoolSize(Pool.PENDING));
    assertEquals(0, wallet.getPoolSize(Pool.UNSPENT));
}

[Buggy Hunk]
tx2.addOutput(valueOf(0, 9), new ECKey());

[Patch]
tx2.addOutput(valueOf(0, 9), someOtherAddress);