Program: 85961
Project: 85961
Buggy source:
@Test public void testDoubleSpendOnForkPending() throws Exception {
  final Transaction[] eventDead=new Transaction[1];
  final Transaction[] eventReplacement=new Transaction[1];
  wallet.addEventListener(new AbstractWalletEventListener(){
    @Override public void onTransactionConfidenceChanged(    Wallet wallet,    Transaction tx){
      super.onTransactionConfidenceChanged(wallet,tx);
      eventDead[0]=tx;
      eventReplacement[0]=tx.getConfidence().getOverridingTransaction();
    }
  }
);
  Block b1=unitTestParams.genesisBlock.createNextBlock(coinsTo);
  chain.add(b1);
  Transaction t1=wallet.createSend(someOtherGuy,Utils.toNanoCoins(10,0));
  Address yetAnotherGuy=new ECKey().toAddress(unitTestParams);
  Transaction t2=wallet.createSend(yetAnotherGuy,Utils.toNanoCoins(20,0));
  wallet.commitTx(t1);
  Block b2=b1.createNextBlock(new ECKey().toAddress(unitTestParams));
  chain.add(b2);
  assertEquals(Utils.toNanoCoins(0,0),wallet.getBalance());
  assertEquals(Utils.toNanoCoins(40,0),wallet.getBalance(Wallet.BalanceType.ESTIMATED));
  Block b3=b1.createNextBlock(new ECKey().toAddress(unitTestParams));
  b3.addTransaction(t2);
  b3.solve();
  chain.add(b3);
  Block b4=b3.createNextBlock(new ECKey().toAddress(unitTestParams));
  chain.add(b4);
  assertEquals(t1,eventDead[0]);
  assertEquals(t2,eventReplacement[0]);
  assertEquals(Utils.toNanoCoins(30,0),wallet.getBalance());
  Block b5=b2.createNextBlock(new ECKey().toAddress(unitTestParams));
  chain.add(b5);
  Block b6=b5.createNextBlock(new ECKey().toAddress(unitTestParams));
  chain.add(b6);
  assertEquals(Utils.toNanoCoins(0,0),wallet.getBalance());
  assertEquals(Utils.toNanoCoins(40,0),wallet.getBalance(Wallet.BalanceType.ESTIMATED));
}

Fixed version (ground truth):
@Test public void testDoubleSpendOnForkPending() throws Exception {
  final Transaction[] eventDead=new Transaction[1];
  final Transaction[] eventReplacement=new Transaction[1];
  wallet.addEventListener(new AbstractWalletEventListener(){
    @Override public void onTransactionConfidenceChanged(    Wallet wallet,    Transaction tx){
      super.onTransactionConfidenceChanged(wallet,tx);
      if (tx.getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.OVERRIDDEN_BY_DOUBLE_SPEND) {
        eventDead[0]=tx;
        eventReplacement[0]=tx.getConfidence().getOverridingTransaction();
      }
    }
  }
);
  Block b1=unitTestParams.genesisBlock.createNextBlock(coinsTo);
  chain.add(b1);
  Transaction t1=wallet.createSend(someOtherGuy,Utils.toNanoCoins(10,0));
  Address yetAnotherGuy=new ECKey().toAddress(unitTestParams);
  Transaction t2=wallet.createSend(yetAnotherGuy,Utils.toNanoCoins(20,0));
  wallet.commitTx(t1);
  Block b2=b1.createNextBlock(new ECKey().toAddress(unitTestParams));
  chain.add(b2);
  assertEquals(Utils.toNanoCoins(0,0),wallet.getBalance());
  assertEquals(Utils.toNanoCoins(40,0),wallet.getBalance(Wallet.BalanceType.ESTIMATED));
  Block b3=b1.createNextBlock(new ECKey().toAddress(unitTestParams));
  b3.addTransaction(t2);
  b3.solve();
  chain.add(b3);
  Block b4=b3.createNextBlock(new ECKey().toAddress(unitTestParams));
  chain.add(b4);
  assertEquals(t1,eventDead[0]);
  assertEquals(t2,eventReplacement[0]);
  assertEquals(Utils.toNanoCoins(30,0),wallet.getBalance());
  Block b5=b2.createNextBlock(new ECKey().toAddress(unitTestParams));
  chain.add(b5);
  Block b6=b5.createNextBlock(new ECKey().toAddress(unitTestParams));
  chain.add(b6);
  assertEquals(Utils.toNanoCoins(0,0),wallet.getBalance());
  assertEquals(Utils.toNanoCoins(40,0),wallet.getBalance(Wallet.BalanceType.ESTIMATED));
}