Program: 85674
Project: 85674
Buggy source:
@SuppressWarnings("String_Node_Str") @Test public void keyRotationHD2() throws Exception {
  Utils.setMockClock();
  ECKey badKey=ECKey.fromPrivate(Utils.HEX.decode("String_Node_Str"));
  badKey.setCreationTimeSeconds(Utils.currentTimeSeconds());
  Utils.rollMockClock(86400);
  ECKey goodKey=ECKey.fromPrivate(Utils.HEX.decode("String_Node_Str"));
  goodKey.setCreationTimeSeconds(Utils.currentTimeSeconds());
  KeyChainGroup kcg=new KeyChainGroup(params);
  kcg.importKeys(badKey,goodKey);
  Utils.rollMockClock(86400);
  wallet=new Wallet(params,kcg);
  wallet.upgradeToDeterministic(null);
  DeterministicKey badWatchingKey=wallet.getWatchingKey();
  assertEquals(badKey.getCreationTimeSeconds(),badWatchingKey.getCreationTimeSeconds());
  sendMoneyToWallet(wallet,CENT,badWatchingKey.toAddress(params),AbstractBlockChain.NewBlockType.BEST_CHAIN);
  wallet.setKeyRotationTime(goodKey.getCreationTimeSeconds());
  List<Transaction> txns=wallet.doMaintenance(null,false).get();
  assertEquals(1,txns.size());
  Address output=txns.get(0).getOutput(0).getAddressFromP2PKHScript(params);
  ECKey usedKey=wallet.findKeyFromPubHash(output.getHash160());
  assertEquals(goodKey.getCreationTimeSeconds(),usedKey.getCreationTimeSeconds());
  assertEquals(goodKey.getCreationTimeSeconds(),wallet.freshReceiveKey().getCreationTimeSeconds());
  assertEquals("String_Node_Str",usedKey.toAddress(params).toString());
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") @Test public void keyRotationHD2() throws Exception {
  Utils.setMockClock();
  ECKey badKey=ECKey.fromPrivate(Utils.HEX.decode("String_Node_Str"));
  badKey.setCreationTimeSeconds(Utils.currentTimeSeconds());
  Utils.rollMockClock(86400);
  ECKey goodKey=ECKey.fromPrivate(Utils.HEX.decode("String_Node_Str"));
  goodKey.setCreationTimeSeconds(Utils.currentTimeSeconds());
  final AtomicReference<List<DeterministicKeyChain>> fChains=new AtomicReference<List<DeterministicKeyChain>>();
  KeyChainGroup kcg=new KeyChainGroup(params){
{
      fChains.set(chains);
    }
  }
;
  kcg.importKeys(badKey,goodKey);
  Utils.rollMockClock(86400);
  wallet=new Wallet(params,kcg);
  assertTrue(fChains.get().isEmpty());
  wallet.upgradeToDeterministic(null);
  DeterministicKey badWatchingKey=wallet.getWatchingKey();
  assertEquals(badKey.getCreationTimeSeconds(),badWatchingKey.getCreationTimeSeconds());
  sendMoneyToWallet(wallet,CENT,badWatchingKey.toAddress(params),AbstractBlockChain.NewBlockType.BEST_CHAIN);
  wallet.setKeyRotationTime(goodKey.getCreationTimeSeconds());
  List<Transaction> txns=wallet.doMaintenance(null,false).get();
  assertEquals(1,txns.size());
  Address output=txns.get(0).getOutput(0).getAddressFromP2PKHScript(params);
  ECKey usedKey=wallet.findKeyFromPubHash(output.getHash160());
  assertEquals(goodKey.getCreationTimeSeconds(),usedKey.getCreationTimeSeconds());
  assertEquals(goodKey.getCreationTimeSeconds(),wallet.freshReceiveKey().getCreationTimeSeconds());
  assertEquals("String_Node_Str",usedKey.toAddress(params).toString());
  DeterministicKeyChain c=fChains.get().get(1);
  assertEquals(c.getEarliestKeyCreationTime(),goodKey.getCreationTimeSeconds());
  assertEquals(2,fChains.get().size());
  wallet.commitTx(txns.get(0));
  assertTrue(wallet.doMaintenance(null,false).get().isEmpty());
  assertEquals(c,fChains.get().get(1));
  assertEquals(2,fChains.get().size());
}