nus-yam/ex-repair huggingface dataset:
Program: 85950
Project: 85950
Buggy source:
/** 
 * The primary BitCoin chain created by Satoshi. 
 */
public static NetworkParameters prodNet(){
  NetworkParameters n=new NetworkParameters();
  n.proofOfWorkLimit=new BigInteger("String_Node_Str",16);
  n.port=8333;
  n.packetMagic=0xf9beb4d9L;
  n.addressHeader=0;
  n.acceptableAddressCodes=new int[]{0};
  n.dumpedPrivateKeyHeader=128;
  n.interval=INTERVAL;
  n.targetTimespan=TARGET_TIMESPAN;
  n.alertSigningKey=SATOSHI_KEY;
  n.genesisBlock=createGenesis(n);
  n.genesisBlock.setDifficultyTarget(0x1d00ffffL);
  n.genesisBlock.setTime(1231006505L);
  n.genesisBlock.setNonce(2083236893);
  n.id=ID_PRODNET;
  n.checkBlockDifficulty=true;
  String genesisHash=n.genesisBlock.getHashAsString();
  checkState(genesisHash.equals("String_Node_Str"),genesisHash);
  return n;
}

Fixed version (ground truth):
/** 
 * The primary BitCoin chain created by Satoshi. 
 */
public static NetworkParameters prodNet(){
  NetworkParameters n=new NetworkParameters();
  n.proofOfWorkLimit=Utils.decodeCompactBits(0x1d00ffffL);
  n.port=8333;
  n.packetMagic=0xf9beb4d9L;
  n.addressHeader=0;
  n.acceptableAddressCodes=new int[]{0};
  n.dumpedPrivateKeyHeader=128;
  n.interval=INTERVAL;
  n.targetTimespan=TARGET_TIMESPAN;
  n.alertSigningKey=SATOSHI_KEY;
  n.genesisBlock=createGenesis(n);
  n.genesisBlock.setDifficultyTarget(0x1d00ffffL);
  n.genesisBlock.setTime(1231006505L);
  n.genesisBlock.setNonce(2083236893);
  n.id=ID_PRODNET;
  String genesisHash=n.genesisBlock.getHashAsString();
  checkState(genesisHash.equals("String_Node_Str"),genesisHash);
  return n;
}
Program: 85951
Project: 85951
Buggy source:
private void processBlock(Block m) throws IOException {
  log.info("String_Node_Str",m.getHashAsString());
  try {
synchronized (pendingGetBlockFutures) {
      for (int i=0; i < pendingGetBlockFutures.size(); i++) {
        GetDataFuture<Block> f=pendingGetBlockFutures.get(i);
        if (f.getItem().hash.equals(m.getHash())) {
          f.setResult(m);
          pendingGetBlockFutures.remove(i);
          return;
        }
      }
    }
    if (blockChain.add(m)) {
      invokeOnBlocksDownloaded(m);
    }
 else {
      blockChainDownload(m.getHash());
    }
  }
 catch (  VerificationException e) {
    log.warn("String_Node_Str",e);
  }
catch (  ScriptException e) {
    log.warn("String_Node_Str",e);
  }
}

Fixed version (ground truth):
private void processBlock(Block m) throws IOException {
  log.debug("String_Node_Str",m.getHashAsString());
  try {
synchronized (pendingGetBlockFutures) {
      for (int i=0; i < pendingGetBlockFutures.size(); i++) {
        GetDataFuture<Block> f=pendingGetBlockFutures.get(i);
        if (f.getItem().hash.equals(m.getHash())) {
          f.setResult(m);
          pendingGetBlockFutures.remove(i);
          return;
        }
      }
    }
    if (blockChain.add(m)) {
      invokeOnBlocksDownloaded(m);
    }
 else {
      blockChainDownload(m.getHash());
    }
  }
 catch (  VerificationException e) {
    log.warn("String_Node_Str",e);
  }
catch (  ScriptException e) {
    log.warn("String_Node_Str",e);
  }
}
Program: 85952
Project: 85952
Buggy source:
@Before public void setUp() throws Exception {
  BriefLogFormatter.initVerbose();
  testNetChain=new BlockChain(testNet,new Wallet(testNet),new MemoryBlockStore(testNet));
  unitTestParams=NetworkParameters.unitTests();
  wallet=new Wallet(unitTestParams){
    @Override public void receiveFromBlock(    Transaction tx,    StoredBlock block,    BlockChain.NewBlockType blockType) throws VerificationException, ScriptException {
      super.receiveFromBlock(tx,block,blockType);
      BlockChainTest.this.block[0]=block;
    }
  }
;
  wallet.addKey(new ECKey());
  resetBlockStore();
  chain=new BlockChain(unitTestParams,wallet,blockStore);
  coinbaseTo=wallet.keychain.get(0).toAddress(unitTestParams);
  testNet.checkBlockDifficulty=true;
}

Fixed version (ground truth):
@Before public void setUp() throws Exception {
  BriefLogFormatter.initVerbose();
  testNetChain=new BlockChain(testNet,new Wallet(testNet),new MemoryBlockStore(testNet));
  unitTestParams=NetworkParameters.unitTests();
  wallet=new Wallet(unitTestParams){
    @Override public void receiveFromBlock(    Transaction tx,    StoredBlock block,    BlockChain.NewBlockType blockType) throws VerificationException, ScriptException {
      super.receiveFromBlock(tx,block,blockType);
      BlockChainTest.this.block[0]=block;
    }
  }
;
  wallet.addKey(new ECKey());
  resetBlockStore();
  chain=new BlockChain(unitTestParams,wallet,blockStore);
  coinbaseTo=wallet.keychain.get(0).toAddress(unitTestParams);
}
Program: 85953
Project: 85953
Buggy source:
private synchronized boolean add(Block block,boolean tryConnecting) throws BlockStoreException, VerificationException, ScriptException {
  if (System.currentTimeMillis() - statsLastTime > 1000) {
    if (statsBlocksAdded > 1)     log.info("String_Node_Str",statsBlocksAdded);
    statsLastTime=System.currentTimeMillis();
    statsBlocksAdded=0;
  }
  if (block.equals(getChainHead().getHeader())) {
    log.debug("String_Node_Str",block.getHash());
    return true;
  }
  boolean contentsImportant=false;
  HashMap<Wallet,List<Transaction>> walletToTxMap=new HashMap<Wallet,List<Transaction>>();
  if (block.transactions != null) {
    scanTransactions(block,walletToTxMap);
    contentsImportant=walletToTxMap.size() > 0;
  }
  try {
    block.verifyHeader();
    if (contentsImportant)     block.verifyTransactions();
  }
 catch (  VerificationException e) {
    log.error("String_Node_Str",e);
    log.error(block.getHashAsString());
    throw e;
  }
  StoredBlock storedPrev=blockStore.get(block.getPrevBlockHash());
  if (storedPrev == null) {
    checkState(tryConnecting,"String_Node_Str");
    log.warn("String_Node_Str",block.getHashAsString());
    unconnectedBlocks.add(block);
    return false;
  }
 else {
    StoredBlock newStoredBlock=storedPrev.build(block);
    checkDifficultyTransitions(storedPrev,newStoredBlock);
    blockStore.put(newStoredBlock);
    connectBlock(newStoredBlock,storedPrev,walletToTxMap);
  }
  if (tryConnecting)   tryConnectingUnconnected();
  statsBlocksAdded++;
  return true;
}

Fixed version (ground truth):
private synchronized boolean add(Block block,boolean tryConnecting) throws BlockStoreException, VerificationException, ScriptException {
  if (System.currentTimeMillis() - statsLastTime > 1000) {
    if (statsBlocksAdded > 1)     log.info("String_Node_Str",statsBlocksAdded);
    statsLastTime=System.currentTimeMillis();
    statsBlocksAdded=0;
  }
  if (block.equals(getChainHead().getHeader())) {
    log.debug("String_Node_Str",block.getHash());
    return true;
  }
  boolean contentsImportant=false;
  if (block.transactions != null) {
    contentsImportant=containsRelevantTransactions(block);
  }
  try {
    block.verifyHeader();
    if (contentsImportant)     block.verifyTransactions();
  }
 catch (  VerificationException e) {
    log.error("String_Node_Str",e);
    log.error(block.getHashAsString());
    throw e;
  }
  StoredBlock storedPrev=blockStore.get(block.getPrevBlockHash());
  if (storedPrev == null) {
    checkState(tryConnecting,"String_Node_Str");
    log.warn("String_Node_Str",block.getHashAsString());
    unconnectedBlocks.add(block);
    return false;
  }
 else {
    StoredBlock newStoredBlock=storedPrev.build(block);
    checkDifficultyTransitions(storedPrev,newStoredBlock);
    blockStore.put(newStoredBlock);
    connectBlock(newStoredBlock,storedPrev,block.transactions);
  }
  if (tryConnecting)   tryConnectingUnconnected();
  statsBlocksAdded++;
  return true;
}
Program: 85954
Project: 85954
Buggy source:
private void connectBlock(StoredBlock newStoredBlock,StoredBlock storedPrev,HashMap<Wallet,List<Transaction>> newTransactions) throws BlockStoreException, VerificationException {
  StoredBlock head=getChainHead();
  if (storedPrev.equals(head)) {
    setChainHead(newStoredBlock);
    log.debug("String_Node_Str",newStoredBlock.getHeight());
    if (newTransactions != null)     sendTransactionsToWallet(newStoredBlock,NewBlockType.BEST_CHAIN,newTransactions);
  }
 else {
    boolean haveNewBestChain=newStoredBlock.moreWorkThan(head);
    if (haveNewBestChain) {
      log.info("String_Node_Str");
    }
 else {
      StoredBlock splitPoint=findSplit(newStoredBlock,head);
      if (splitPoint == newStoredBlock) {
        log.debug("String_Node_Str",newStoredBlock.getHeight(),newStoredBlock.getHeader().getHash());
        return;
      }
      if (splitPoint == null) {
        log.error("String_Node_Str");
      }
 else {
        int splitPointHeight=splitPoint.getHeight();
        String splitPointHash=splitPoint.getHeader().getHashAsString();
        log.info("String_Node_Str",new Object[]{splitPointHeight,splitPointHash,newStoredBlock});
      }
    }
    if (newTransactions != null) {
      sendTransactionsToWallet(newStoredBlock,NewBlockType.SIDE_CHAIN,newTransactions);
    }
    if (haveNewBestChain)     handleNewBestChain(newStoredBlock);
  }
}

Fixed version (ground truth):
private void connectBlock(StoredBlock newStoredBlock,StoredBlock storedPrev,List<Transaction> transactions) throws BlockStoreException, VerificationException {
  StoredBlock head=getChainHead();
  if (storedPrev.equals(head)) {
    setChainHead(newStoredBlock);
    log.debug("String_Node_Str",newStoredBlock.getHeight());
    if (transactions != null)     sendTransactionsToWallet(newStoredBlock,NewBlockType.BEST_CHAIN,transactions);
  }
 else {
    boolean haveNewBestChain=newStoredBlock.moreWorkThan(head);
    if (haveNewBestChain) {
      log.info("String_Node_Str");
    }
 else {
      StoredBlock splitPoint=findSplit(newStoredBlock,head);
      if (splitPoint == newStoredBlock) {
        log.warn("String_Node_Str",newStoredBlock.getHeight(),newStoredBlock.getHeader().getHash());
        return;
      }
      if (splitPoint == null) {
        log.error("String_Node_Str");
      }
 else {
        int splitPointHeight=splitPoint.getHeight();
        String splitPointHash=splitPoint.getHeader().getHashAsString();
        log.info("String_Node_Str",new Object[]{splitPointHeight,splitPointHash,newStoredBlock});
      }
    }
    if (transactions != null) {
      sendTransactionsToWallet(newStoredBlock,NewBlockType.SIDE_CHAIN,transactions);
    }
    if (haveNewBestChain)     handleNewBestChain(newStoredBlock);
  }
}
Program: 85955
Project: 85955
Buggy source:
private void sendTransactionsToWallet(StoredBlock block,NewBlockType blockType,HashMap<Wallet,List<Transaction>> newTransactions) throws VerificationException {
  for (  Map.Entry<Wallet,List<Transaction>> entry : newTransactions.entrySet()) {
    try {
      List<Transaction> txns=entry.getValue();
      for (      Transaction tx : txns) {
        entry.getKey().receiveFromBlock(tx,block,blockType);
      }
    }
 catch (    ScriptException e) {
      log.warn("String_Node_Str" + e.toString());
    }
  }
}

Fixed version (ground truth):
private void sendTransactionsToWallet(StoredBlock block,NewBlockType blockType,List<Transaction> transactions) throws VerificationException {
  for (  Transaction tx : transactions) {
    for (    Wallet wallet : wallets) {
      try {
        if (wallet.isTransactionRelevant(tx,true))         wallet.receiveFromBlock(tx,block,blockType);
      }
 catch (      ScriptException e) {
        log.warn("String_Node_Str" + e.toString());
      }
    }
  }
}
Program: 85956
Project: 85956
Buggy source:
@Test public void testStorage() throws Exception {
  File temp=File.createTempFile("String_Node_Str",null,null);
  System.out.println(temp.getAbsolutePath());
  temp.deleteOnExit();
  NetworkParameters params=NetworkParameters.unitTests();
  Address to=new ECKey().toAddress(params);
  BoundedOverheadBlockStore store=new BoundedOverheadBlockStore(params,temp);
  StoredBlock genesis=store.getChainHead();
  assertEquals(params.genesisBlock,genesis.getHeader());
  StoredBlock b1=genesis.build(genesis.getHeader().createNextBlock(to).cloneAsHeader());
  store.put(b1);
  store.setChainHead(b1);
  store.close();
  store=new BoundedOverheadBlockStore(params,temp);
  StoredBlock b2=store.get(b1.getHeader().getHash());
  assertEquals(b1,b2);
  assertEquals(b1,store.getChainHead());
}

Fixed version (ground truth):
@Test public void testStorage() throws Exception {
  File temp=folder.newFile("String_Node_Str");
  System.out.println(temp.getAbsolutePath());
  NetworkParameters params=NetworkParameters.unitTests();
  Address to=new ECKey().toAddress(params);
  BoundedOverheadBlockStore store=new BoundedOverheadBlockStore(params,temp);
  StoredBlock genesis=store.getChainHead();
  assertEquals(params.genesisBlock,genesis.getHeader());
  StoredBlock b1=genesis.build(genesis.getHeader().createNextBlock(to).cloneAsHeader());
  store.put(b1);
  store.setChainHead(b1);
  store.close();
  store=new BoundedOverheadBlockStore(params,temp);
  StoredBlock b2=store.get(b1.getHeader().getHash());
  assertEquals(b1,b2);
  assertEquals(b1,store.getChainHead());
}
Program: 85957
Project: 85957
Buggy source:
@Test public void testLocking() throws Exception {
  File temp=File.createTempFile("String_Node_Str",null,null);
  System.out.println(temp.getAbsolutePath());
  temp.deleteOnExit();
  NetworkParameters params=NetworkParameters.unitTests();
  BoundedOverheadBlockStore store=new BoundedOverheadBlockStore(params,temp);
  try {
    BoundedOverheadBlockStore store1=new BoundedOverheadBlockStore(params,temp);
    fail();
  }
 catch (  BlockStoreException e) {
  }
}

Fixed version (ground truth):
@Test public void testLocking() throws Exception {
  File temp=folder.newFile("String_Node_Str");
  System.out.println(temp.getAbsolutePath());
  NetworkParameters params=NetworkParameters.unitTests();
  BoundedOverheadBlockStore store=new BoundedOverheadBlockStore(params,temp);
  try {
    BoundedOverheadBlockStore store1=new BoundedOverheadBlockStore(params,temp);
    fail();
  }
 catch (  BlockStoreException e) {
  }
}
Program: 85958
Project: 85958
Buggy source:
@Test public void testStorage() throws Exception {
  deleteRecursively(new File(DB_NAME));
  NetworkParameters params=NetworkParameters.unitTests();
  Address to=new ECKey().toAddress(params);
  DerbyBlockStore store=new DerbyBlockStore(params,DB_NAME);
  store.resetStore();
  store.dump();
  StoredBlock genesis=store.getChainHead();
  assertEquals(params.genesisBlock,genesis.getHeader());
  StoredBlock b1=genesis.build(genesis.getHeader().createNextBlock(to).cloneAsHeader());
  store.put(b1);
  store.setChainHead(b1);
  store.dump();
  store=new DerbyBlockStore(params,DB_NAME);
  StoredBlock b2=store.get(b1.getHeader().getHash());
  assertEquals(b1,b2);
  assertEquals(b1,store.getChainHead());
  StoredBlock g1=store.get(params.genesisBlock.getHash());
  assertEquals(params.genesisBlock,g1.getHeader());
  store.dump();
  store.close();
}

Fixed version (ground truth):
@Test public void testStorage() throws Exception {
  File file=new File(folder.getRoot(),"String_Node_Str");
  String path=file.getAbsolutePath();
  NetworkParameters params=NetworkParameters.unitTests();
  Address to=new ECKey().toAddress(params);
  DerbyBlockStore store=new DerbyBlockStore(params,path);
  store.resetStore();
  store.dump();
  StoredBlock genesis=store.getChainHead();
  assertEquals(params.genesisBlock,genesis.getHeader());
  StoredBlock b1=genesis.build(genesis.getHeader().createNextBlock(to).cloneAsHeader());
  store.put(b1);
  store.setChainHead(b1);
  store.dump();
  store=new DerbyBlockStore(params,path);
  StoredBlock b2=store.get(b1.getHeader().getHash());
  assertEquals(b1,b2);
  assertEquals(b1,store.getChainHead());
  StoredBlock g1=store.get(params.genesisBlock.getHash());
  assertEquals(params.genesisBlock,g1.getHeader());
  store.dump();
  store.close();
}
Program: 85959
Project: 85959
Buggy source:
@Before public void setUp() throws IOException {
  temp=File.createTempFile("String_Node_Str",null,null);
  System.out.println(temp.getAbsolutePath());
  params=NetworkParameters.unitTests();
  to=new ECKey().toAddress(params);
}

Fixed version (ground truth):
@Before public void setUp() throws IOException {
  temp=folder.newFile("String_Node_Str");
  System.out.println(temp.getAbsolutePath());
  params=NetworkParameters.unitTests();
  to=new ECKey().toAddress(params);
}
Program: 85960
Project: 85960
Buggy source:
@Override public void onTransactionConfidenceChanged(Wallet wallet,Transaction tx){
  super.onTransactionConfidenceChanged(wallet,tx);
  eventDead[0]=tx;
  eventReplacement[0]=tx.getConfidence().getOverridingTransaction();
}

Fixed version (ground truth):
@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();
  }
}
Program: 85962
Project: 85962
Buggy source:
private synchronized boolean add(Block block,boolean tryConnecting) throws BlockStoreException, VerificationException, ScriptException {
  if (System.currentTimeMillis() - statsLastTime > 1000) {
    if (statsBlocksAdded > 1)     log.info("String_Node_Str",statsBlocksAdded);
    statsLastTime=System.currentTimeMillis();
    statsBlocksAdded=0;
  }
  if (block.equals(chainHead.getHeader())) {
    return true;
  }
  boolean contentsImportant=false;
  HashMap<Wallet,List<Transaction>> walletToTxMap=new HashMap<Wallet,List<Transaction>>();
  if (block.transactions != null) {
    scanTransactions(block,walletToTxMap);
    contentsImportant=walletToTxMap.size() > 0;
  }
  try {
    block.verifyHeader();
    if (contentsImportant)     block.verifyTransactions();
  }
 catch (  VerificationException e) {
    log.error("String_Node_Str",e);
    log.error(block.getHashAsString());
    throw e;
  }
  StoredBlock storedPrev=blockStore.get(block.getPrevBlockHash());
  if (storedPrev == null) {
    log.warn("String_Node_Str",block.getHashAsString());
    unconnectedBlocks.add(block);
    return false;
  }
 else {
    StoredBlock newStoredBlock=storedPrev.build(block);
    checkDifficultyTransitions(storedPrev,newStoredBlock);
    blockStore.put(newStoredBlock);
    connectBlock(newStoredBlock,storedPrev,walletToTxMap);
  }
  if (tryConnecting)   tryConnectingUnconnected();
  statsBlocksAdded++;
  return true;
}

Fixed version (ground truth):
private synchronized boolean add(Block block,boolean tryConnecting) throws BlockStoreException, VerificationException, ScriptException {
}
Program: 85963
Project: 85963
Buggy source:
/** 
 * For each block in unconnectedBlocks, see if we can now fit it on top of the chain and if so, do so.
 */
private void tryConnectingUnconnected() throws VerificationException, ScriptException, BlockStoreException {
  int blocksConnectedThisRound;
  do {
    blocksConnectedThisRound=0;
    Iterator<Block> iter=unconnectedBlocks.iterator();
    while (iter.hasNext()) {
      Block block=iter.next();
      StoredBlock prev=blockStore.get(block.getPrevBlockHash());
      if (prev == null) {
        continue;
      }
      add(block,false);
      iter.remove();
      blocksConnectedThisRound++;
    }
    if (blocksConnectedThisRound > 0) {
      log.info("String_Node_Str",blocksConnectedThisRound);
    }
  }
 while (blocksConnectedThisRound > 0);
}

Fixed version (ground truth):
/** 
 * For each block in unconnectedBlocks, see if we can now fit it on top of the chain and if so, do so.
 */
private void tryConnectingUnconnected() throws VerificationException, ScriptException, BlockStoreException {
  int blocksConnectedThisRound;
  do {
    blocksConnectedThisRound=0;
    Iterator<Block> iter=unconnectedBlocks.iterator();
    while (iter.hasNext()) {
      Block block=iter.next();
      log.debug("String_Node_Str",block.getHash());
      StoredBlock prev=blockStore.get(block.getPrevBlockHash());
      if (prev == null) {
        log.debug("String_Node_Str");
        continue;
      }
      add(block,false);
      iter.remove();
      blocksConnectedThisRound++;
    }
    if (blocksConnectedThisRound > 0) {
      log.info("String_Node_Str",blocksConnectedThisRound);
    }
  }
 while (blocksConnectedThisRound > 0);
}
Program: 85964
Project: 85964
Buggy source:
/** 
 * Locates the point in the chain at which newStoredBlock and chainHead diverge. Returns null if no split point was found (ie they are part of the same chain).
 */
private StoredBlock findSplit(StoredBlock newChainHead,StoredBlock chainHead) throws BlockStoreException {
}

Fixed version (ground truth):
/** 
 * Locates the point in the chain at which newStoredBlock and chainHead diverge. Returns null if no split point was found (ie they are not part of the same chain). Returns newChainHead or chainHead if they don't actually diverge but are part of the same chain.
 */
private StoredBlock findSplit(StoredBlock newChainHead,StoredBlock chainHead) throws BlockStoreException {
}
Program: 85965
Project: 85965
Buggy source:
private void connectBlock(StoredBlock newStoredBlock,StoredBlock storedPrev,HashMap<Wallet,List<Transaction>> newTransactions) throws BlockStoreException, VerificationException {
  if (storedPrev.equals(chainHead)) {
    setChainHead(newStoredBlock);
    log.debug("String_Node_Str",chainHead.getHeight());
    if (newTransactions != null)     sendTransactionsToWallet(newStoredBlock,NewBlockType.BEST_CHAIN,newTransactions);
  }
 else {
    boolean haveNewBestChain=newStoredBlock.moreWorkThan(chainHead);
    if (haveNewBestChain) {
      log.info("String_Node_Str");
    }
 else {
      StoredBlock splitPoint=findSplit(newStoredBlock,chainHead);
      String splitPointHash=splitPoint != null ? splitPoint.getHeader().getHashAsString() : "String_Node_Str";
      log.info("String_Node_Str",splitPointHash,newStoredBlock);
    }
    if (newTransactions != null) {
      sendTransactionsToWallet(newStoredBlock,NewBlockType.SIDE_CHAIN,newTransactions);
    }
    if (haveNewBestChain)     handleNewBestChain(newStoredBlock);
  }
}

Fixed version (ground truth):
private void connectBlock(StoredBlock newStoredBlock,StoredBlock storedPrev,HashMap<Wallet,List<Transaction>> newTransactions) throws BlockStoreException, VerificationException {
  if (storedPrev.equals(chainHead)) {
    setChainHead(newStoredBlock);
    log.debug("String_Node_Str",chainHead.getHeight());
    if (newTransactions != null)     sendTransactionsToWallet(newStoredBlock,NewBlockType.BEST_CHAIN,newTransactions);
  }
 else {
    boolean haveNewBestChain=newStoredBlock.moreWorkThan(chainHead);
    if (haveNewBestChain) {
      log.info("String_Node_Str");
    }
 else {
      StoredBlock splitPoint=findSplit(newStoredBlock,chainHead);
      if (splitPoint == newStoredBlock) {
        log.debug("String_Node_Str",newStoredBlock.getHeight(),newStoredBlock.getHeader().getHash());
        return;
      }
      int splitPointHeight=splitPoint != null ? splitPoint.getHeight() : -1;
      String splitPointHash=splitPoint != null ? splitPoint.getHeader().getHashAsString() : "String_Node_Str";
      log.info("String_Node_Str",new Object[]{splitPointHeight,splitPointHash,newStoredBlock});
    }
    if (newTransactions != null) {
      sendTransactionsToWallet(newStoredBlock,NewBlockType.SIDE_CHAIN,newTransactions);
    }
    if (haveNewBestChain)     handleNewBestChain(newStoredBlock);
  }
}
Program: 85966
Project: 85966
Buggy source:
@Before public void setUp() throws Exception {
  testNetChain=new BlockChain(testNet,new Wallet(testNet),new MemoryBlockStore(testNet));
  unitTestParams=NetworkParameters.unitTests();
  wallet=new Wallet(unitTestParams);
  wallet.addKey(new ECKey());
  resetBlockStore();
  chain=new BlockChain(unitTestParams,wallet,blockStore);
  coinbaseTo=wallet.keychain.get(0).toAddress(unitTestParams);
}

Fixed version (ground truth):
@Before public void setUp() throws Exception {
  BriefLogFormatter.initVerbose();
  testNetChain=new BlockChain(testNet,new Wallet(testNet),new MemoryBlockStore(testNet));
  unitTestParams=NetworkParameters.unitTests();
  wallet=new Wallet(unitTestParams){
    @Override public void receiveFromBlock(    Transaction tx,    StoredBlock block,    BlockChain.NewBlockType blockType) throws VerificationException, ScriptException {
      super.receiveFromBlock(tx,block,blockType);
      BlockChainTest.this.block[0]=block;
    }
  }
;
  wallet.addKey(new ECKey());
  resetBlockStore();
  chain=new BlockChain(unitTestParams,wallet,blockStore);
  coinbaseTo=wallet.keychain.get(0).toAddress(unitTestParams);
}
Program: 85967
Project: 85967
Buggy source:
private void blockChainDownload(Sha256Hash toHash) throws IOException {
  log.info("String_Node_Str",toHash.toString());
  List<Sha256Hash> blockLocator=new LinkedList<Sha256Hash>();
  blockLocator.add(params.genesisBlock.getHash());
  Block topBlock=blockChain.getChainHead().getHeader();
  if (!topBlock.equals(params.genesisBlock)) {
    if (!topBlock.getPrevBlockHash().equals(params.genesisBlock)) {
      blockLocator.add(0,topBlock.getPrevBlockHash());
    }
    blockLocator.add(0,topBlock.getHash());
  }
  if (downloadBlockBodies) {
    GetBlocksMessage message=new GetBlocksMessage(params,blockLocator,toHash);
    conn.writeMessage(message);
  }
 else {
    GetHeadersMessage message=new GetHeadersMessage(params,blockLocator,toHash);
    conn.writeMessage(message);
  }
}

Fixed version (ground truth):
private void blockChainDownload(Sha256Hash toHash) throws IOException {
  log.info("String_Node_Str",toHash.toString());
  List<Sha256Hash> blockLocator=new LinkedList<Sha256Hash>();
  blockLocator.add(params.genesisBlock.getHash());
  Block topBlock=blockChain.getChainHead().getHeader();
  if (!topBlock.equals(params.genesisBlock)) {
    if (!topBlock.getPrevBlockHash().equals(params.genesisBlock.getHash())) {
      blockLocator.add(0,topBlock.getPrevBlockHash());
    }
    blockLocator.add(0,topBlock.getHash());
  }
  if (downloadBlockBodies) {
    GetBlocksMessage message=new GetBlocksMessage(params,blockLocator,toHash);
    conn.writeMessage(message);
  }
 else {
    GetHeadersMessage message=new GetHeadersMessage(params,blockLocator,toHash);
    conn.writeMessage(message);
  }
}
Program: 85969
Project: 85969
Buggy source:
@Test public void unconnectedBlock() throws Exception {
  Block b1=TestUtils.createFakeBlock(unitTestParams,blockStore).block;
  blockChain.add(b1);
  Block b2=TestUtils.makeSolvedTestBlock(unitTestParams,b1);
  Block b3=TestUtils.makeSolvedTestBlock(unitTestParams,b2);
  conn.inbound(b3);
  runPeer(peer,conn);
  GetBlocksMessage getblocks=(GetBlocksMessage)conn.popOutbound();
  List<Sha256Hash> expectedLocator=new ArrayList<Sha256Hash>();
  expectedLocator.add(b1.getHash());
  expectedLocator.add(b1.getPrevBlockHash());
  expectedLocator.add(unitTestParams.genesisBlock.getHash());
  assertEquals(getblocks.getLocator(),expectedLocator);
  assertEquals(getblocks.getStopHash(),b3.getHash());
}

Fixed version (ground truth):
@Test public void unconnectedBlock() throws Exception {
  Block b1=TestUtils.createFakeBlock(unitTestParams,blockStore).block;
  blockChain.add(b1);
  Block b2=TestUtils.makeSolvedTestBlock(unitTestParams,b1);
  blockChain.add(b2);
  Block b3=TestUtils.makeSolvedTestBlock(unitTestParams,b2);
  Block b4=TestUtils.makeSolvedTestBlock(unitTestParams,b3);
  conn.inbound(b4);
  runPeer(peer,conn);
  GetBlocksMessage getblocks=(GetBlocksMessage)conn.popOutbound();
  List<Sha256Hash> expectedLocator=new ArrayList<Sha256Hash>();
  expectedLocator.add(b2.getHash());
  expectedLocator.add(b2.getPrevBlockHash());
  expectedLocator.add(unitTestParams.genesisBlock.getHash());
  assertEquals(expectedLocator,getblocks.getLocator());
  assertEquals(b4.getHash(),getblocks.getStopHash());
}
Program: 85970
Project: 85970
Buggy source:
@Test public void invTickle() throws Exception {
  Block b1=TestUtils.createFakeBlock(unitTestParams,blockStore).block;
  blockChain.add(b1);
  Block b2=TestUtils.makeSolvedTestBlock(unitTestParams,b1);
  Block b3=TestUtils.makeSolvedTestBlock(unitTestParams,b2);
  conn.inbound(b3);
  InventoryMessage inv=new InventoryMessage(unitTestParams);
  InventoryItem item=new InventoryItem(InventoryItem.Type.Block,b3.getHash());
  inv.addItem(item);
  conn.inbound(inv);
  runPeer(peer,conn);
  GetBlocksMessage getblocks=(GetBlocksMessage)conn.popOutbound();
  List<Sha256Hash> expectedLocator=new ArrayList<Sha256Hash>();
  expectedLocator.add(b1.getHash());
  expectedLocator.add(b1.getPrevBlockHash());
  expectedLocator.add(unitTestParams.genesisBlock.getHash());
  assertEquals(getblocks.getLocator(),expectedLocator);
  assertEquals(getblocks.getStopHash(),b3.getHash());
}

Fixed version (ground truth):
@Test public void invTickle() throws Exception {
  Block b1=TestUtils.createFakeBlock(unitTestParams,blockStore).block;
  blockChain.add(b1);
  Block b2=TestUtils.makeSolvedTestBlock(unitTestParams,b1);
  Block b3=TestUtils.makeSolvedTestBlock(unitTestParams,b2);
  conn.inbound(b3);
  InventoryMessage inv=new InventoryMessage(unitTestParams);
  InventoryItem item=new InventoryItem(InventoryItem.Type.Block,b3.getHash());
  inv.addItem(item);
  conn.inbound(inv);
  runPeer(peer,conn);
  GetBlocksMessage getblocks=(GetBlocksMessage)conn.popOutbound();
  List<Sha256Hash> expectedLocator=new ArrayList<Sha256Hash>();
  expectedLocator.add(b1.getHash());
  expectedLocator.add(unitTestParams.genesisBlock.getHash());
  assertEquals(getblocks.getLocator(),expectedLocator);
  assertEquals(getblocks.getStopHash(),b3.getHash());
}
Program: 85971
Project: 85971
Buggy source:
/** 
 * Returns the time at which the block was solved and broadcast, according to the clock of the solving node.
 */
public Date getTime(){
  return new Date(getTimeSeconds());
}

Fixed version (ground truth):
/** 
 * Returns the time at which the block was solved and broadcast, according to the clock of the solving node.
 */
public Date getTime(){
  return new Date(getTimeSeconds() * 1000);
}
Program: 85972
Project: 85972
Buggy source:
/** 
 * @return true if every output is marked as spent.
 */
public boolean isEveryOutputSpent(){
  maybeParse();
  for (  TransactionOutput output : outputs) {
    if (output.isAvailableForSpending())     return false;
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Returns true if every output is marked as spent.
 */
public boolean isEveryOutputSpent(){
  maybeParse();
  for (  TransactionOutput output : outputs) {
    if (output.isAvailableForSpending())     return false;
  }
  return true;
}
Program: 85973
Project: 85973
Buggy source:
/** 
 * If the transactions outputs are all marked as spent, and it's in the unspent map, move it.
 */
private void maybeMoveTxToSpent(Transaction tx,String context){
  if (tx.isEveryOutputSpent()) {
    if (unspent.remove(tx.getHash()) != null) {
      if (log.isInfoEnabled()) {
        log.info("String_Node_Str" + context + "String_Node_Str");
        log.info("String_Node_Str" + context + "String_Node_Str");
      }
      spent.put(tx.getHash(),tx);
    }
  }
}

Fixed version (ground truth):
/** 
 * If the transactions outputs are all marked as spent, and it's in the unspent map, move it.
 */
private void maybeMoveTxToSpent(Transaction tx,String context){
  if (tx.isEveryOwnedOutputSpent(this)) {
    if (unspent.remove(tx.getHash()) != null) {
      if (log.isInfoEnabled()) {
        log.info("String_Node_Str" + context + "String_Node_Str");
        log.info("String_Node_Str" + context + "String_Node_Str");
      }
      spent.put(tx.getHash(),tx);
    }
  }
}
Program: 85974
Project: 85974
Buggy source:
public static Transaction createFakeTx(NetworkParameters params,BigInteger nanocoins,Address to){
  Transaction t=new Transaction(params);
  TransactionOutput o1=new TransactionOutput(params,t,nanocoins,to);
  t.addOutput(o1);
  Transaction prevTx=new Transaction(params);
  TransactionOutput prevOut=new TransactionOutput(params,prevTx,nanocoins,to);
  prevTx.addOutput(prevOut);
  t.addInput(prevOut);
  return t;
}

Fixed version (ground truth):
public static Transaction createFakeTx(NetworkParameters params,BigInteger nanocoins,Address to){
  Transaction t=new Transaction(params);
  TransactionOutput outputToMe=new TransactionOutput(params,t,nanocoins,to);
  t.addOutput(outputToMe);
  TransactionOutput change=new TransactionOutput(params,t,Utils.toNanoCoins(1,11),new ECKey().toAddress(params));
  t.addOutput(change);
  Transaction prevTx=new Transaction(params);
  TransactionOutput prevOut=new TransactionOutput(params,prevTx,nanocoins,to);
  prevTx.addOutput(prevOut);
  t.addInput(prevOut);
  return t;
}
Program: 85975
Project: 85975
Buggy source:
@Test public void balance() throws Exception {
  BigInteger v1=toNanoCoins(5,0);
  BigInteger v2=toNanoCoins(0,50);
  Transaction t1=createFakeTx(params,v1,myAddress);
  Transaction t2=createFakeTx(params,v2,myAddress);
  StoredBlock b1=createFakeBlock(params,blockStore,t1).storedBlock;
  StoredBlock b2=createFakeBlock(params,blockStore,t2).storedBlock;
  BigInteger expected=toNanoCoins(5,50);
  wallet.receive(t1,b1,BlockChain.NewBlockType.BEST_CHAIN);
  wallet.receive(t2,b2,BlockChain.NewBlockType.BEST_CHAIN);
  assertEquals(expected,wallet.getBalance());
  BigInteger v3=toNanoCoins(1,0);
  Transaction spend=wallet.createSend(new ECKey().toAddress(params),v3);
  wallet.confirmSend(spend);
  assertEquals(toNanoCoins(4,50),wallet.getBalance(Wallet.BalanceType.ESTIMATED));
  assertFalse(wallet.getBalance(Wallet.BalanceType.AVAILABLE).equals(wallet.getBalance(Wallet.BalanceType.ESTIMATED)));
  StoredBlock b3=createFakeBlock(params,blockStore,spend).storedBlock;
  wallet.receive(spend,b3,BlockChain.NewBlockType.BEST_CHAIN);
  BigInteger v4=toNanoCoins(4,50);
  assertEquals(v4,wallet.getBalance(Wallet.BalanceType.AVAILABLE));
}

Fixed version (ground truth):
@Test public void balance() throws Exception {
  BigInteger v1=toNanoCoins(5,0);
  BigInteger v2=toNanoCoins(0,50);
  Transaction t1=createFakeTx(params,v1,myAddress);
  Transaction t2=createFakeTx(params,v2,myAddress);
  StoredBlock b1=createFakeBlock(params,blockStore,t1).storedBlock;
  StoredBlock b2=createFakeBlock(params,blockStore,t2).storedBlock;
  BigInteger expected=toNanoCoins(5,50);
  assertEquals(0,wallet.getPoolSize(Wallet.Pool.ALL));
  wallet.receive(t1,b1,BlockChain.NewBlockType.BEST_CHAIN);
  assertEquals(1,wallet.getPoolSize(Wallet.Pool.UNSPENT));
  wallet.receive(t2,b2,BlockChain.NewBlockType.BEST_CHAIN);
  assertEquals(2,wallet.getPoolSize(Wallet.Pool.UNSPENT));
  assertEquals(expected,wallet.getBalance());
  BigInteger v3=toNanoCoins(1,0);
  Transaction spend=wallet.createSend(new ECKey().toAddress(params),v3);
  wallet.confirmSend(spend);
  assertEquals(1,wallet.getPoolSize(Wallet.Pool.UNSPENT));
  assertEquals(1,wallet.getPoolSize(Wallet.Pool.SPENT));
  assertEquals(1,wallet.getPoolSize(Wallet.Pool.PENDING));
  assertEquals(toNanoCoins(4,50),wallet.getBalance(Wallet.BalanceType.ESTIMATED));
  assertFalse(wallet.getBalance(Wallet.BalanceType.AVAILABLE).equals(wallet.getBalance(Wallet.BalanceType.ESTIMATED)));
  StoredBlock b3=createFakeBlock(params,blockStore,spend).storedBlock;
  wallet.receive(spend,b3,BlockChain.NewBlockType.BEST_CHAIN);
  BigInteger v4=toNanoCoins(4,50);
  assertEquals(v4,wallet.getBalance(Wallet.BalanceType.AVAILABLE));
}
Program: 85976
Project: 85976
Buggy source:
private void runListeners(){
  for (int i=0; i < listeners.size(); i++) {
    Listener l=listeners.get(i);
synchronized (l) {
      l.onConfidenceChanged(transaction);
    }
    if (listeners.get(i) != l) {
      i--;
    }
  }
}

Fixed version (ground truth):
private void runListeners(){
  if (listeners == null)   return;
  for (int i=0; i < listeners.size(); i++) {
    Listener l=listeners.get(i);
synchronized (l) {
      l.onConfidenceChanged(transaction);
    }
    if (listeners.get(i) != l) {
      i--;
    }
  }
}
Program: 85977
Project: 85977
Buggy source:
/** 
 * <p>Adds an event listener that will be run when this confidence object is updated. The listener will be locked and is likely to be invoked on a peer thread.</p> <p>Note that this is NOT called when every block is arrived. Instead it is called when the transaction  transitions between confidence states, ie, from not being seen in the chain to being seen (not necessarily in  the best chain). If you want to know when the transaction gets buried under another block, listen for new block events using   {@link PeerEventListener#onBlocksDownloaded(Peer,Block,int)} and then use the getters on theconfidence object to determine the new depth.</p>
 */
public synchronized void addEventListener(Listener listener){
  if (listener == null)   throw new IllegalArgumentException("String_Node_Str");
  listeners.add(listener);
}

Fixed version (ground truth):
/** 
 * <p>Adds an event listener that will be run when this confidence object is updated. The listener will be locked and is likely to be invoked on a peer thread.</p> <p>Note that this is NOT called when every block is arrived. Instead it is called when the transaction  transitions between confidence states, ie, from not being seen in the chain to being seen (not necessarily in  the best chain). If you want to know when the transaction gets buried under another block, listen for new block events using   {@link PeerEventListener#onBlocksDownloaded(Peer,Block,int)} and then use the getters on theconfidence object to determine the new depth.</p>
 */
public synchronized void addEventListener(Listener listener){
  if (listener == null)   throw new IllegalArgumentException("String_Node_Str");
  if (listeners == null)   listeners=new ArrayList<Listener>(1);
  listeners.add(listener);
}
Program: 85978
Project: 85978
Buggy source:
public void run(){
  try {
    if (shouldConnect) {
      log.info("String_Node_Str" + peer);
      peer.connect();
    }
    peers.add(peer);
    handleNewPeer(peer);
    if (blockUntilRunning == ExecuteBlockMode.WAIT_FOR_STARTUP)     latch.countDown();
    peer.run();
  }
 catch (  PeerException ex) {
    final Throwable cause=ex.getCause();
    if (cause instanceof SocketTimeoutException) {
      log.info("String_Node_Str" + peer + "String_Node_Str"+ cause.getMessage());
    }
 else     if (cause instanceof ConnectException) {
      log.info("String_Node_Str" + peer + "String_Node_Str"+ cause.getMessage());
    }
 else     if (cause instanceof IOException) {
      log.info("String_Node_Str" + peer + "String_Node_Str"+ cause.getMessage());
    }
 else {
      log.error("String_Node_Str" + peer,ex);
    }
  }
 finally {
    if (!running)     return;
    peer.disconnect();
    if (address != null)     inactives.add(address);
    if (peers.remove(peer))     handlePeerDeath(peer);
  }
}

Fixed version (ground truth):
public void run(){
  try {
    if (shouldConnect) {
      log.info("String_Node_Str" + peer);
      peer.connect();
    }
synchronized (PeerGroup.this) {
      if (!running) {
        peer.disconnect();
        return;
      }
      peers.add(peer);
    }
    handleNewPeer(peer);
    if (blockUntilRunning == ExecuteBlockMode.WAIT_FOR_STARTUP)     latch.countDown();
    peer.run();
  }
 catch (  PeerException ex) {
    final Throwable cause=ex.getCause();
    if (cause instanceof SocketTimeoutException) {
      log.info("String_Node_Str" + peer + "String_Node_Str"+ cause.getMessage());
    }
 else     if (cause instanceof ConnectException) {
      log.info("String_Node_Str" + peer + "String_Node_Str"+ cause.getMessage());
    }
 else     if (cause instanceof IOException) {
      log.info("String_Node_Str" + peer + "String_Node_Str"+ cause.getMessage());
    }
 else {
      log.error("String_Node_Str" + peer,ex);
    }
  }
 finally {
    if (!running)     return;
    peer.disconnect();
    if (address != null)     inactives.add(address);
    if (peers.remove(peer))     handlePeerDeath(peer);
  }
}
Program: 85980
Project: 85980
Buggy source:
static BigInteger decodeCompactBits(long compact){
  int size=((int)(compact >> 24)) & 0xFF;
  byte[] bytes=new byte[4 + size];
  bytes[3]=(byte)size;
  if (size >= 1)   bytes[4]=(byte)((compact >> 16) & 0xFF);
  if (size >= 2)   bytes[5]=(byte)((compact >> 8) & 0xFF);
  if (size >= 3)   bytes[6]=(byte)((compact >> 0) & 0xFF);
  return decodeMPI(bytes);
}

Fixed version (ground truth):
public static BigInteger decodeCompactBits(long compact){
  int size=((int)(compact >> 24)) & 0xFF;
  byte[] bytes=new byte[4 + size];
  bytes[3]=(byte)size;
  if (size >= 1)   bytes[4]=(byte)((compact >> 16) & 0xFF);
  if (size >= 2)   bytes[5]=(byte)((compact >> 8) & 0xFF);
  if (size >= 3)   bytes[6]=(byte)((compact >> 0) & 0xFF);
  return decodeMPI(bytes);
}
Program: 85981
Project: 85981
Buggy source:
@Override public void onChainDownloadStarted(Peer peer,int blocksLeft){
  startDownload(blocksLeft);
  originalBlocksLeft=blocksLeft;
}

Fixed version (ground truth):
@Override public void onChainDownloadStarted(Peer peer,int blocksLeft){
  startDownload(blocksLeft);
  originalBlocksLeft=blocksLeft;
  if (blocksLeft == 0) {
    doneDownload();
    done.release();
  }
}
Program: 85982
Project: 85982
Buggy source:
/** 
 * Starts an asynchronous download of the block chain. The chain download is deemed to be complete once we've downloaded the same number of blocks that the peer advertised having in its version handshake message.
 */
public void startBlockChainDownload() throws IOException {
  setDownloadData(true);
  if (getPeerBlocksToGet() > 0) {
    for (    PeerEventListener listener : eventListeners) {
synchronized (listener) {
        listener.onChainDownloadStarted(this,getPeerBlocksToGet());
      }
    }
    blockChainDownload(Sha256Hash.ZERO_HASH);
  }
}

Fixed version (ground truth):
/** 
 * Starts an asynchronous download of the block chain. The chain download is deemed to be complete once we've downloaded the same number of blocks that the peer advertised having in its version handshake message.
 */
public void startBlockChainDownload() throws IOException {
  setDownloadData(true);
  if (getPeerBlocksToGet() >= 0) {
    for (    PeerEventListener listener : eventListeners) {
synchronized (listener) {
        listener.onChainDownloadStarted(this,getPeerBlocksToGet());
      }
    }
    blockChainDownload(Sha256Hash.ZERO_HASH);
  }
}
Program: 85983
Project: 85983
Buggy source:
/** 
 * Depending on the environment, this should normally be between 1 and 10, default is 4.
 * @param maxConnections the maximum number of peer connections that this group will try to make.
 */
public synchronized void setMaxConnections(int maxConnections){
  peerPool.setMaximumPoolSize(maxConnections);
}

Fixed version (ground truth):
/** 
 * Depending on the environment, this should normally be between 1 and 10, default is 4.
 * @param maxConnections the maximum number of peer connections that this group will try to make.
 */
public synchronized void setMaxConnections(int maxConnections){
  peerPool.setCorePoolSize(Math.min(maxConnections,DEFAULT_CONNECTIONS));
  peerPool.setMaximumPoolSize(maxConnections);
}
Program: 85984
Project: 85984
Buggy source:
@Test public void singleDownloadPeer2() throws Exception {
  MockNetworkConnection n1=createMockNetworkConnection();
  Peer p1=new Peer(params,blockChain,n1);
  MockNetworkConnection n2=createMockNetworkConnection();
  Peer p2=new Peer(params,blockChain,n2);
  peerGroup.start();
  peerGroup.addPeer(p1);
  Block b1=TestUtils.createFakeBlock(params,blockStore).block;
  Block b2=TestUtils.makeSolvedTestBlock(params,b1);
  Block b3=TestUtils.makeSolvedTestBlock(params,b2);
  n1.setVersionMessageForHeight(params,3);
  n2.setVersionMessageForHeight(params,3);
  peerGroup.startBlockChainDownload(new AbstractPeerEventListener(){
  }
);
  GetBlocksMessage getblocks=(GetBlocksMessage)n1.outbound();
  assertEquals(Sha256Hash.ZERO_HASH,getblocks.getStopHash());
  InventoryMessage inv=new InventoryMessage(params);
  inv.addItem(new InventoryItem(InventoryItem.Type.Block,b1.getHash()));
  inv.addItem(new InventoryItem(InventoryItem.Type.Block,b2.getHash()));
  inv.addItem(new InventoryItem(InventoryItem.Type.Block,b3.getHash()));
  n1.inbound(inv);
  GetDataMessage getdata=(GetDataMessage)n1.outbound();
  n1.inbound(b1);
  peerGroup.addPeer(p2);
  Message message=n2.outbound();
  assertNull(message == null ? "String_Node_Str" : message.toString(),message);
}

Fixed version (ground truth):
@Test public void singleDownloadPeer2() throws Exception {
  MockNetworkConnection n1=createMockNetworkConnection();
  Peer p1=new Peer(params,blockChain,n1);
  MockNetworkConnection n2=createMockNetworkConnection();
  Peer p2=new Peer(params,blockChain,n2);
  peerGroup.start();
  peerGroup.addPeer(p1);
  Block b1=TestUtils.createFakeBlock(params,blockStore).block;
  Block b2=TestUtils.makeSolvedTestBlock(params,b1);
  Block b3=TestUtils.makeSolvedTestBlock(params,b2);
  n1.setVersionMessageForHeight(params,3);
  n2.setVersionMessageForHeight(params,3);
  peerGroup.startBlockChainDownload(new AbstractPeerEventListener(){
  }
);
  GetBlocksMessage getblocks=(GetBlocksMessage)n1.outbound();
  assertEquals(Sha256Hash.ZERO_HASH,getblocks.getStopHash());
  InventoryMessage inv=new InventoryMessage(params);
  inv.addItem(new InventoryItem(InventoryItem.Type.Block,b1.getHash()));
  inv.addItem(new InventoryItem(InventoryItem.Type.Block,b2.getHash()));
  inv.addItem(new InventoryItem(InventoryItem.Type.Block,b3.getHash()));
  n1.inbound(inv);
  @SuppressWarnings("String_Node_Str") GetDataMessage getdata=(GetDataMessage)n1.outbound();
  n1.inbound(b1);
  peerGroup.addPeer(p2);
  Message message=n2.outbound();
  assertNull(message == null ? "String_Node_Str" : message.toString(),message);
}
Program: 85985
Project: 85985
Buggy source:
@Test public void singleDownloadPeer1() throws Exception {
  MockNetworkConnection n1=createMockNetworkConnection();
  Peer p1=new Peer(params,blockChain,n1);
  MockNetworkConnection n2=createMockNetworkConnection();
  Peer p2=new Peer(params,blockChain,n2);
  peerGroup.start();
  peerGroup.addPeer(p1);
  peerGroup.addPeer(p2);
  Block b1=TestUtils.createFakeBlock(params,blockStore).block;
  blockChain.add(b1);
  Block b2=TestUtils.makeSolvedTestBlock(params,b1);
  Block b3=TestUtils.makeSolvedTestBlock(params,b2);
  InventoryMessage inv=new InventoryMessage(params);
  inv.addItem(new InventoryItem(InventoryItem.Type.Block,b3.getHash()));
  n1.inbound(inv);
  n2.inbound(inv);
  assertTrue(n1.outbound() instanceof GetDataMessage);
  assertNull(n2.outbound());
  disconnectAndWait(n1);
  n2.inbound(inv);
  assertTrue(n2.outbound() instanceof GetDataMessage);
  peerGroup.stop();
}

Fixed version (ground truth):
@Test public void singleDownloadPeer1() throws Exception {
  MockNetworkConnection n1=createMockNetworkConnection();
  Peer p1=new Peer(params,blockChain,n1);
  MockNetworkConnection n2=createMockNetworkConnection();
  Peer p2=new Peer(params,blockChain,n2);
  peerGroup.start();
  peerGroup.addPeer(p1);
  peerGroup.addPeer(p2);
  assertEquals(2,peerGroup.numPeers());
  List<Peer> tmp=peerGroup.getPeers();
  assertEquals(p1,tmp.get(0));
  assertEquals(p2,tmp.get(1));
  Block b1=TestUtils.createFakeBlock(params,blockStore).block;
  blockChain.add(b1);
  Block b2=TestUtils.makeSolvedTestBlock(params,b1);
  Block b3=TestUtils.makeSolvedTestBlock(params,b2);
  InventoryMessage inv=new InventoryMessage(params);
  inv.addItem(new InventoryItem(InventoryItem.Type.Block,b3.getHash()));
  n1.inbound(inv);
  n2.inbound(inv);
  assertTrue(n1.outbound() instanceof GetDataMessage);
  assertNull(n2.outbound());
  disconnectAndWait(n1);
  n2.inbound(inv);
  assertTrue(n2.outbound() instanceof GetDataMessage);
  peerGroup.stop();
}