Program: 85763
Project: 85763
Buggy source:
@Test public void pending1() throws Exception {
  final BigInteger nanos=Utils.toNanoCoins(1,0);
  final Transaction t1=createFakeTx(params,nanos,myAddress);
  final boolean[] flags=new boolean[2];
  final Transaction[] notifiedTx=new Transaction[1];
  final int[] walletChanged=new int[1];
  wallet.addEventListener(new AbstractWalletEventListener(){
    @Override public void onCoinsReceived(    Wallet wallet,    Transaction tx,    BigInteger prevBalance,    BigInteger newBalance){
      assertEquals(tx,t1);
      assertEquals(prevBalance,BigInteger.ZERO);
      assertEquals(newBalance,nanos);
      flags[0]=true;
      flags[1]=tx.isPending();
      notifiedTx[0]=tx;
    }
    @Override public void onWalletChanged(    Wallet wallet){
      walletChanged[0]++;
    }
  }
);
  if (wallet.isPendingTransactionRelevant(t1))   wallet.receivePending(t1,null);
  Threading.waitForUserCode();
  assertTrue(flags[0]);
  assertTrue(flags[1]);
  flags[0]=false;
  assertFalse(wallet.isPendingTransactionRelevant(t1));
  assertFalse(flags[0]);
  flags[0]=flags[1]=false;
  notifiedTx[0].getConfidence().addEventListener(new TransactionConfidence.Listener(){
    public void onConfidenceChanged(    Transaction tx,    TransactionConfidence.Listener.ChangeReason reason){
      flags[1]=true;
    }
  }
);
  assertEquals(TransactionConfidence.ConfidenceType.PENDING,notifiedTx[0].getConfidence().getConfidenceType());
  final Transaction t1Copy=new Transaction(params,t1.bitcoinSerialize());
  sendMoneyToWallet(t1Copy,AbstractBlockChain.NewBlockType.BEST_CHAIN);
  Threading.waitForUserCode();
  assertFalse(flags[0]);
  assertTrue(flags[1]);
  assertEquals(TransactionConfidence.ConfidenceType.BUILDING,notifiedTx[0].getConfidence().getConfidenceType());
  flags[0]=false;
  flags[1]=false;
  Transaction irrelevant=createFakeTx(params,nanos,new ECKey().toAddress(params));
  if (wallet.isPendingTransactionRelevant(irrelevant))   wallet.receivePending(irrelevant,null);
  Threading.waitForUserCode();
  assertFalse(flags[0]);
  assertEquals(2,walletChanged[0]);
}

Fixed version (ground truth):
@Test public void pending1() throws Exception {
  final BigInteger nanos=Utils.toNanoCoins(1,0);
  final Transaction t1=createFakeTx(params,nanos,myAddress);
  final boolean[] flags=new boolean[2];
  final Transaction[] notifiedTx=new Transaction[1];
  final int[] walletChanged=new int[1];
  wallet.addEventListener(new AbstractWalletEventListener(){
    @Override public void onCoinsReceived(    Wallet wallet,    Transaction tx,    BigInteger prevBalance,    BigInteger newBalance){
      assertEquals(tx,t1);
      assertEquals(prevBalance,BigInteger.ZERO);
      assertEquals(newBalance,nanos);
      flags[0]=true;
      flags[1]=tx.isPending();
      notifiedTx[0]=tx;
    }
    @Override public void onWalletChanged(    Wallet wallet){
      walletChanged[0]++;
    }
  }
);
  if (wallet.isPendingTransactionRelevant(t1))   wallet.receivePending(t1,null);
  Threading.waitForUserCode();
  assertTrue(flags[0]);
  assertTrue(flags[1]);
  flags[0]=false;
  assertFalse(wallet.isPendingTransactionRelevant(t1));
  assertFalse(flags[0]);
  flags[0]=flags[1]=false;
  final TransactionConfidence.Listener.ChangeReason[] reasons=new TransactionConfidence.Listener.ChangeReason[1];
  notifiedTx[0].getConfidence().addEventListener(new TransactionConfidence.Listener(){
    public void onConfidenceChanged(    Transaction tx,    TransactionConfidence.Listener.ChangeReason reason){
      flags[1]=true;
      reasons[0]=reason;
    }
  }
);
  assertEquals(TransactionConfidence.ConfidenceType.PENDING,notifiedTx[0].getConfidence().getConfidenceType());
  wallet.notifyNewBestBlock(createFakeBlock(blockStore).storedBlock);
  Threading.waitForUserCode();
  assertNull(reasons[0]);
  final Transaction t1Copy=new Transaction(params,t1.bitcoinSerialize());
  sendMoneyToWallet(t1Copy,AbstractBlockChain.NewBlockType.BEST_CHAIN);
  Threading.waitForUserCode();
  assertFalse(flags[0]);
  assertTrue(flags[1]);
  assertEquals(TransactionConfidence.ConfidenceType.BUILDING,notifiedTx[0].getConfidence().getConfidenceType());
  flags[0]=false;
  flags[1]=false;
  Transaction irrelevant=createFakeTx(params,nanos,new ECKey().toAddress(params));
  if (wallet.isPendingTransactionRelevant(irrelevant))   wallet.receivePending(irrelevant,null);
  Threading.waitForUserCode();
  assertFalse(flags[0]);
  assertEquals(3,walletChanged[0]);
}