Program: 85825
Project: 85825
Buggy source:
@Test public void doubleSpendFinneyAttack() throws Exception {
  final Transaction[] eventDead=new Transaction[1];
  final Transaction[] eventReplacement=new Transaction[1];
  final int[] eventWalletChanged=new int[1];
  wallet.addEventListener(new AbstractWalletEventListener(){
    @Override public void onTransactionConfidenceChanged(    Wallet wallet,    Transaction tx){
      super.onTransactionConfidenceChanged(wallet,tx);
      if (tx.getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.DEAD) {
        eventDead[0]=tx;
        eventReplacement[0]=tx.getConfidence().getOverridingTransaction();
      }
    }
    @Override public void onWalletChanged(    Wallet wallet){
      eventWalletChanged[0]++;
    }
  }
);
  BigInteger nanos=Utils.toNanoCoins(1,0);
  sendMoneyToWallet(nanos,AbstractBlockChain.NewBlockType.BEST_CHAIN);
  Transaction send1=wallet.createSend(new ECKey().toAddress(params),toNanoCoins(0,50));
  Transaction send2=wallet.createSend(new ECKey().toAddress(params),toNanoCoins(0,50));
  send2=new Transaction(params,send2.bitcoinSerialize());
  wallet.commitTx(send1);
  sendMoneyToWallet(send2,AbstractBlockChain.NewBlockType.BEST_CHAIN);
  assertEquals(send1,eventDead[0]);
  assertEquals(send2,eventReplacement[0]);
  assertEquals(TransactionConfidence.ConfidenceType.DEAD,send1.getConfidence().getConfidenceType());
  TestUtils.DoubleSpends doubleSpends=TestUtils.createFakeDoubleSpendTxns(params,myAddress);
  wallet.receivePending(doubleSpends.t1,null);
  assertEquals(TransactionConfidence.ConfidenceType.NOT_SEEN_IN_CHAIN,doubleSpends.t1.getConfidence().getConfidenceType());
  sendMoneyToWallet(doubleSpends.t2,AbstractBlockChain.NewBlockType.BEST_CHAIN);
  assertEquals(TransactionConfidence.ConfidenceType.DEAD,doubleSpends.t1.getConfidence().getConfidenceType());
  assertEquals(doubleSpends.t2,doubleSpends.t1.getConfidence().getOverridingTransaction());
  assertEquals(5,eventWalletChanged[0]);
}

Fixed version (ground truth):
@Test public void doubleSpendFinneyAttack() throws Exception {
  final Transaction[] eventDead=new Transaction[1];
  final Transaction[] eventReplacement=new Transaction[1];
  final int[] eventWalletChanged=new int[1];
  wallet.addEventListener(new AbstractWalletEventListener(){
    @Override public void onTransactionConfidenceChanged(    Wallet wallet,    Transaction tx){
      super.onTransactionConfidenceChanged(wallet,tx);
      if (tx.getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.DEAD) {
        eventDead[0]=tx;
        eventReplacement[0]=tx.getConfidence().getOverridingTransaction();
      }
    }
    @Override public void onWalletChanged(    Wallet wallet){
      eventWalletChanged[0]++;
    }
  }
);
  BigInteger nanos=Utils.toNanoCoins(1,0);
  sendMoneyToWallet(nanos,AbstractBlockChain.NewBlockType.BEST_CHAIN);
  Transaction received=wallet.getTransactions(false,false).iterator().next();
  Transaction send1=wallet.createSend(new ECKey().toAddress(params),toNanoCoins(0,50));
  Transaction send2=wallet.createSend(new ECKey().toAddress(params),toNanoCoins(0,50));
  send2=new Transaction(params,send2.bitcoinSerialize());
  wallet.commitTx(send1);
  assertEquals(send1,received.getOutput(0).getSpentBy().getParentTransaction());
  sendMoneyToWallet(send2,AbstractBlockChain.NewBlockType.BEST_CHAIN);
  assertEquals(send1,eventDead[0]);
  assertEquals(send2,eventReplacement[0]);
  assertEquals(TransactionConfidence.ConfidenceType.DEAD,send1.getConfidence().getConfidenceType());
  assertEquals(send2,received.getOutput(0).getSpentBy().getParentTransaction());
  TestUtils.DoubleSpends doubleSpends=TestUtils.createFakeDoubleSpendTxns(params,myAddress);
  wallet.receivePending(doubleSpends.t1,null);
  assertEquals(TransactionConfidence.ConfidenceType.NOT_SEEN_IN_CHAIN,doubleSpends.t1.getConfidence().getConfidenceType());
  sendMoneyToWallet(doubleSpends.t2,AbstractBlockChain.NewBlockType.BEST_CHAIN);
  assertEquals(TransactionConfidence.ConfidenceType.DEAD,doubleSpends.t1.getConfidence().getConfidenceType());
  assertEquals(doubleSpends.t2,doubleSpends.t1.getConfidence().getOverridingTransaction());
  assertEquals(5,eventWalletChanged[0]);
}