nus-yam/ex-repair huggingface dataset:
Program: 85852
Project: 85852
Buggy source:
@Test public void insertSerializeTest(){
  BloomFilter filter=new BloomFilter(3,0.01,0,BloomFilter.bloomUpdate.UPDATE_ALL);
  filter.insert(Hex.decode("String_Node_Str"));
  assertTrue(filter.contains(Hex.decode("String_Node_Str")));
  assertFalse(filter.contains(Hex.decode("String_Node_Str")));
  filter.insert(Hex.decode("String_Node_Str"));
  assertTrue(filter.contains(Hex.decode("String_Node_Str")));
  filter.insert(Hex.decode("String_Node_Str"));
  assertTrue(filter.contains(Hex.decode("String_Node_Str")));
  assertTrue(Arrays.equals(Hex.decode("String_Node_Str"),filter.bitcoinSerialize()));
}

Fixed version (ground truth):
@Test public void insertSerializeTest(){
  BloomFilter filter=new BloomFilter(3,0.01,0,BloomFilter.BloomUpdate.UPDATE_ALL);
  filter.insert(Hex.decode("String_Node_Str"));
  assertTrue(filter.contains(Hex.decode("String_Node_Str")));
  assertFalse(filter.contains(Hex.decode("String_Node_Str")));
  filter.insert(Hex.decode("String_Node_Str"));
  assertTrue(filter.contains(Hex.decode("String_Node_Str")));
  filter.insert(Hex.decode("String_Node_Str"));
  assertTrue(filter.contains(Hex.decode("String_Node_Str")));
  assertTrue(Arrays.equals(Hex.decode("String_Node_Str"),filter.bitcoinSerialize()));
}
Program: 85853
Project: 85853
Buggy source:
private int hash(int hashNum,byte[] object){
  int h1=(int)((hashNum * 0xFBA4C795L + nTweak) & 0xFFFFFFFF);
  final int c1=0xcc9e2d51;
  final int c2=0x1b873593;
  int numBlocks=(object.length / 4) * 4;
  for (int i=0; i < numBlocks; i+=4) {
    int k1=(object[i] & 0xFF) | ((object[i + 1] & 0xFF) << 8) | ((object[i + 2] & 0xFF) << 16)| ((object[i + 3] & 0xFF) << 24);
    k1*=c1;
    k1=ROTL32(k1,15);
    k1*=c2;
    h1^=k1;
    h1=ROTL32(h1,13);
    h1=h1 * 5 + 0xe6546b64;
  }
  int k1=0;
switch (object.length & 3) {
case 3:
    k1^=(object[numBlocks + 2] & 0xff) << 16;
case 2:
  k1^=(object[numBlocks + 1] & 0xff) << 8;
case 1:
k1^=(object[numBlocks] & 0xff);
k1*=c1;
k1=ROTL32(k1,15);
k1*=c2;
h1^=k1;
}
;
h1^=object.length;
h1^=h1 >>> 16;
h1*=0x85ebca6b;
h1^=h1 >>> 13;
h1*=0xc2b2ae35;
h1^=h1 >>> 16;
return (int)((h1 & 0xFFFFFFFFL) % (data.length * 8));
}

Fixed version (ground truth):
private int hash(int hashNum,byte[] object){
  int h1=(int)((hashNum * 0xFBA4C795L + nTweak) & 0xFFFFFFFF);
  final int c1=0xcc9e2d51;
  final int c2=0x1b873593;
  int numBlocks=(object.length / 4) * 4;
  for (int i=0; i < numBlocks; i+=4) {
    int k1=(object[i] & 0xFF) | ((object[i + 1] & 0xFF) << 8) | ((object[i + 2] & 0xFF) << 16)| ((object[i + 3] & 0xFF) << 24);
    k1*=c1;
    k1=ROTL32(k1,15);
    k1*=c2;
    h1^=k1;
    h1=ROTL32(h1,13);
    h1=h1 * 5 + 0xe6546b64;
  }
  int k1=0;
switch (object.length & 3) {
case 3:
    k1^=(object[numBlocks + 2] & 0xff) << 16;
case 2:
  k1^=(object[numBlocks + 1] & 0xff) << 8;
case 1:
k1^=(object[numBlocks] & 0xff);
k1*=c1;
k1=ROTL32(k1,15);
k1*=c2;
h1^=k1;
default :
break;
}
;
h1^=object.length;
h1^=h1 >>> 16;
h1*=0x85ebca6b;
h1^=h1 >>> 13;
h1*=0xc2b2ae35;
h1^=h1 >>> 16;
return (int)((h1 & 0xFFFFFFFFL) % (data.length * 8));
}
Program: 85855
Project: 85855
Buggy source:
/** 
 * Returns true if the given height has a recorded checkpoint.
 * @param height
 * @return
 */
public boolean isCheckpoint(int height){
  Sha256Hash checkpointHash=checkpoints.get(new Integer(height));
  if (checkpointHash != null)   return true;
  return false;
}

Fixed version (ground truth):
/** 
 * Returns true if the given height has a recorded checkpoint.
 * @param height
 * @return
 */
public boolean isCheckpoint(int height){
  Sha256Hash checkpointHash=checkpoints.get(Integer.valueOf(height));
  if (checkpointHash != null)   return true;
  return false;
}
Program: 85856
Project: 85856
Buggy source:
/** 
 * Returns true if the block height is either not a checkpoint, or is a checkpoint and the hash matches.
 */
public boolean passesCheckpoint(int height,Sha256Hash hash){
  Sha256Hash checkpointHash=checkpoints.get(new Integer(height));
  if (checkpointHash != null)   return checkpointHash.equals(hash);
  return true;
}

Fixed version (ground truth):
/** 
 * Returns true if the block height is either not a checkpoint, or is a checkpoint and the hash matches.
 */
public boolean passesCheckpoint(int height,Sha256Hash hash){
  Sha256Hash checkpointHash=checkpoints.get(Integer.valueOf(height));
  if (checkpointHash != null)   return checkpointHash.equals(hash);
  return true;
}
Program: 85858
Project: 85858
Buggy source:
public void serializeToStream(OutputStream bos) throws IOException {
  Utils.uint64ToByteStreamLE(value,bos);
  bos.write((int)(0xFF & (scriptBytes.length >> 0)));
  bos.write((int)(0xFF & (scriptBytes.length >> 8)));
  bos.write((int)(0xFF & (scriptBytes.length >> 16)));
  bos.write((int)(0xFF & (scriptBytes.length >> 24)));
  bos.write(scriptBytes);
  bos.write(hash.getBytes());
  Utils.uint32ToByteStreamLE(index,bos);
  bos.write((int)(0xFF & (height >> 0)));
  bos.write((int)(0xFF & (height >> 8)));
  bos.write((int)(0xFF & (height >> 16)));
  bos.write((int)(0xFF & (height >> 24)));
}

Fixed version (ground truth):
public void serializeToStream(OutputStream bos) throws IOException {
  Utils.uint64ToByteStreamLE(value,bos);
  bos.write(0xFF & scriptBytes.length >> 0);
  bos.write(0xFF & scriptBytes.length >> 8);
  bos.write(0xFF & (scriptBytes.length >> 16));
  bos.write(0xFF & (scriptBytes.length >> 24));
  bos.write(scriptBytes);
  bos.write(hash.getBytes());
  Utils.uint32ToByteStreamLE(index,bos);
  bos.write(0xFF & (height >> 0));
  bos.write(0xFF & (height >> 8));
  bos.write(0xFF & (height >> 16));
  bos.write(0xFF & (height >> 24));
}
Program: 85859
Project: 85859
Buggy source:
public StoredTransactionOutput(InputStream in) throws IOException {
  byte[] valueBytes=new byte[8];
  in.read(valueBytes,0,8);
  value=BigInteger.valueOf(Utils.readInt64(valueBytes,0));
  int scriptBytesLength=((in.read() & 0xFF) << 0) | ((in.read() & 0xFF) << 8) | ((in.read() & 0xFF) << 16)| ((in.read() & 0xFF) << 24);
  scriptBytes=new byte[scriptBytesLength];
  if (in.read(scriptBytes) != scriptBytesLength)   throw new EOFException();
  byte[] hashBytes=new byte[32];
  if (in.read(hashBytes) != 32)   throw new EOFException();
  hash=new Sha256Hash(hashBytes);
  byte[] indexBytes=new byte[4];
  if (in.read(indexBytes) != 4)   throw new EOFException();
  index=Utils.readUint32(indexBytes,0);
  height=((in.read() & 0xFF) << 0) | ((in.read() & 0xFF) << 8) | ((in.read() & 0xFF) << 16)| ((in.read() & 0xFF) << 24);
}

Fixed version (ground truth):
public StoredTransactionOutput(InputStream in) throws IOException {
  byte[] valueBytes=new byte[8];
  if (in.read(valueBytes,0,8) != 8)   throw new EOFException();
  value=BigInteger.valueOf(Utils.readInt64(valueBytes,0));
  int scriptBytesLength=((in.read() & 0xFF) << 0) | ((in.read() & 0xFF) << 8) | ((in.read() & 0xFF) << 16)| ((in.read() & 0xFF) << 24);
  scriptBytes=new byte[scriptBytesLength];
  if (in.read(scriptBytes) != scriptBytesLength)   throw new EOFException();
  byte[] hashBytes=new byte[32];
  if (in.read(hashBytes) != 32)   throw new EOFException();
  hash=new Sha256Hash(hashBytes);
  byte[] indexBytes=new byte[4];
  if (in.read(indexBytes) != 4)   throw new EOFException();
  index=Utils.readUint32(indexBytes,0);
  height=((in.read() & 0xFF) << 0) | ((in.read() & 0xFF) << 8) | ((in.read() & 0xFF) << 16)| ((in.read() & 0xFF) << 24);
}
Program: 85860
Project: 85860
Buggy source:
public void serializeToStream(OutputStream bos) throws IOException {
  int numOutsCreated=txOutsCreated.size();
  bos.write((int)(0xFF & (numOutsCreated >> 0)));
  bos.write((int)(0xFF & (numOutsCreated >> 8)));
  bos.write((int)(0xFF & (numOutsCreated >> 16)));
  bos.write((int)(0xFF & (numOutsCreated >> 24)));
  for (  StoredTransactionOutput output : txOutsCreated) {
    output.serializeToStream(bos);
  }
  int numOutsSpent=txOutsSpent.size();
  bos.write((int)(0xFF & (numOutsSpent >> 0)));
  bos.write((int)(0xFF & (numOutsSpent >> 8)));
  bos.write((int)(0xFF & (numOutsSpent >> 16)));
  bos.write((int)(0xFF & (numOutsSpent >> 24)));
  for (  StoredTransactionOutput output : txOutsSpent) {
    output.serializeToStream(bos);
  }
}

Fixed version (ground truth):
public void serializeToStream(OutputStream bos) throws IOException {
  int numOutsCreated=txOutsCreated.size();
  bos.write(0xFF & (numOutsCreated >> 0));
  bos.write(0xFF & (numOutsCreated >> 8));
  bos.write(0xFF & (numOutsCreated >> 16));
  bos.write(0xFF & (numOutsCreated >> 24));
  for (  StoredTransactionOutput output : txOutsCreated) {
    output.serializeToStream(bos);
  }
  int numOutsSpent=txOutsSpent.size();
  bos.write(0xFF & (numOutsSpent >> 0));
  bos.write(0xFF & (numOutsSpent >> 8));
  bos.write(0xFF & (numOutsSpent >> 16));
  bos.write(0xFF & (numOutsSpent >> 24));
  for (  StoredTransactionOutput output : txOutsSpent) {
    output.serializeToStream(bos);
  }
}
Program: 85861
Project: 85861
Buggy source:
@Test public void badDifficulty() throws Exception {
  assertTrue(testNetChain.add(getBlock1()));
  Block b2=getBlock2();
  assertTrue(testNetChain.add(b2));
  NetworkParameters params2=NetworkParameters.testNet();
  Block bad=new Block(params2);
  bad.setMerkleRoot(new Sha256Hash("String_Node_Str"));
  bad.setNonce(140548933);
  bad.setTime(1279242649);
  bad.setPrevBlockHash(b2.getHash());
  bad.setDifficultyTarget(Block.EASIEST_DIFFICULTY_TARGET);
  try {
    testNetChain.add(bad);
    fail();
  }
 catch (  VerificationException e) {
    assertTrue(e.getMessage(),e.getCause().getMessage().indexOf("String_Node_Str") >= 0);
  }
  params2.proofOfWorkLimit=new BigInteger("String_Node_Str",16);
  try {
    testNetChain.add(bad);
    fail();
  }
 catch (  VerificationException e) {
    assertTrue(e.getMessage(),e.getCause().getMessage().indexOf("String_Node_Str") >= 0);
  }
}

Fixed version (ground truth):
@Test public void badDifficulty() throws Exception {
  assertTrue(testNetChain.add(getBlock1()));
  Block b2=getBlock2();
  assertTrue(testNetChain.add(b2));
  Block bad=new Block(testNet);
  bad.setMerkleRoot(new Sha256Hash("String_Node_Str"));
  bad.setNonce(140548933);
  bad.setTime(1279242649);
  bad.setPrevBlockHash(b2.getHash());
  bad.setDifficultyTarget(Block.EASIEST_DIFFICULTY_TARGET);
  try {
    testNetChain.add(bad);
    fail();
  }
 catch (  VerificationException e) {
    assertTrue(e.getMessage(),e.getCause().getMessage().indexOf("String_Node_Str") >= 0);
  }
  BigInteger oldVal=testNet.proofOfWorkLimit;
  testNet.proofOfWorkLimit=new BigInteger("String_Node_Str",16);
  try {
    testNetChain.add(bad);
    fail();
  }
 catch (  VerificationException e) {
    assertTrue(e.getMessage(),e.getCause().getMessage().indexOf("String_Node_Str") >= 0);
  }
  testNet.proofOfWorkLimit=oldVal;
}
Program: 85862
Project: 85862
Buggy source:
@Before public void setUp() throws Exception {
  BriefLogFormatter.init();
  unitTestParams=NetworkParameters.unitTests();
  unitTestParams.interval=10000;
  store=new MemoryFullPrunedBlockStore(unitTestParams,UNDOABLE_BLOCKS_STORED);
  chain=new FullPrunedBlockChain(unitTestParams,store);
}

Fixed version (ground truth):
@Before public void setUp() throws Exception {
  BriefLogFormatter.init();
  unitTestParams=NetworkParameters.unitTests();
  oldInterval=unitTestParams.interval;
  unitTestParams.interval=10000;
  store=new MemoryFullPrunedBlockStore(unitTestParams,UNDOABLE_BLOCKS_STORED);
  chain=new FullPrunedBlockChain(unitTestParams,store);
}
Program: 85863
Project: 85863
Buggy source:
/** 
 * Catch any exceptions, logging them and then closing the channel. 
 */
@Override public void exceptionCaught(ChannelHandlerContext ctx,ExceptionEvent e) throws Exception {
  String s;
  PeerAddress addr=address.get();
  s=address == null ? "String_Node_Str" : address.toString();
  if (e.getCause() instanceof ConnectException || e.getCause() instanceof IOException) {
    log.info(s + "String_Node_Str" + e.getCause().getMessage());
  }
 else {
    log.warn(s + "String_Node_Str",e.getCause());
  }
  e.getChannel().close();
}

Fixed version (ground truth):
/** 
 * Catch any exceptions, logging them and then closing the channel. 
 */
@Override public void exceptionCaught(ChannelHandlerContext ctx,ExceptionEvent e) throws Exception {
  String s;
  PeerAddress addr=address.get();
  s=addr == null ? "String_Node_Str" : addr.toString();
  if (e.getCause() instanceof ConnectException || e.getCause() instanceof IOException) {
    log.info(s + "String_Node_Str" + e.getCause().getMessage());
  }
 else {
    log.warn(s + "String_Node_Str",e.getCause());
  }
  e.getChannel().close();
}
Program: 85864
Project: 85864
Buggy source:
private synchronized void processHeaders(HeadersMessage m) throws IOException, ProtocolException {
  Preconditions.checkState(!downloadBlockBodies,toString());
  try {
    for (int i=0; i < m.getBlockHeaders().size(); i++) {
      Block header=m.getBlockHeaders().get(i);
      if (header.getTimeSeconds() < fastCatchupTimeSecs) {
        if (blockChain.add(header)) {
          invokeOnBlocksDownloaded(header);
        }
 else {
          throw new ProtocolException("String_Node_Str" + header.getHashAsString());
        }
      }
 else {
        log.info("String_Node_Str",m.getBlockHeaders().size() - i);
        downloadBlockBodies=true;
        lastGetBlocksBegin=Sha256Hash.ZERO_HASH;
        blockChainDownload(Sha256Hash.ZERO_HASH);
        return;
      }
    }
    if (m.getBlockHeaders().size() >= HeadersMessage.MAX_HEADERS)     blockChainDownload(Sha256Hash.ZERO_HASH);
  }
 catch (  VerificationException e) {
    log.warn("String_Node_Str",e);
  }
catch (  PrunedException e) {
    throw new RuntimeException(e);
  }
}

Fixed version (ground truth):
private synchronized void processHeaders(HeadersMessage m) throws IOException, ProtocolException {
  Preconditions.checkState(!downloadBlockBodies,toString());
  try {
    for (int i=0; i < m.getBlockHeaders().size(); i++) {
      Block header=m.getBlockHeaders().get(i);
      if (header.getTimeSeconds() < fastCatchupTimeSecs) {
        if (!downloadData.get()) {
          log.info("String_Node_Str");
          return;
        }
        if (blockChain.add(header)) {
          invokeOnBlocksDownloaded(header);
        }
 else {
          throw new ProtocolException("String_Node_Str" + header.getHashAsString());
        }
      }
 else {
        log.info("String_Node_Str",m.getBlockHeaders().size() - i);
        downloadBlockBodies=true;
        lastGetBlocksBegin=Sha256Hash.ZERO_HASH;
        blockChainDownload(Sha256Hash.ZERO_HASH);
        return;
      }
    }
    if (m.getBlockHeaders().size() >= HeadersMessage.MAX_HEADERS)     blockChainDownload(Sha256Hash.ZERO_HASH);
  }
 catch (  VerificationException e) {
    log.warn("String_Node_Str",e);
  }
catch (  PrunedException e) {
    throw new RuntimeException(e);
  }
}
Program: 85865
Project: 85865
Buggy source:
/** 
 * Handle when a transaction becomes newly active on the best chain, either due to receiving a new block or a re-org making inactive transactions active.
 */
private void processTxFromBestChain(Transaction tx) throws VerificationException {
  boolean isDeadCoinbase=tx.isCoinBase() && dead.containsKey(tx.getHash());
  if (isDeadCoinbase) {
    log.info("String_Node_Str",tx.getHashAsString(),tx.getConfidence().getConfidenceType().name());
    dead.remove(tx.getHash());
  }
  if (inactive.containsKey(tx.getHash())) {
    log.info("String_Node_Str",tx.getHashAsString());
    inactive.remove(tx.getHash());
  }
  updateForSpends(tx,true);
  if (!tx.getValueSentToMe(this).equals(BigInteger.ZERO)) {
    log.info("String_Node_Str",tx.getHashAsString());
    addWalletTransaction(Pool.UNSPENT,tx);
  }
 else   if (!tx.getValueSentFromMe(this).equals(BigInteger.ZERO)) {
    log.info("String_Node_Str",tx.getHashAsString());
    addWalletTransaction(Pool.SPENT,tx);
  }
 else {
    Transaction doubleSpend=findDoubleSpendAgainstPending(tx);
    if (doubleSpend == null)     throw new IllegalStateException("String_Node_Str");
    log.warn("String_Node_Str",doubleSpend.getHashAsString());
    log.warn("String_Node_Str");
    pending.remove(doubleSpend.getHash());
    addWalletTransaction(Pool.DEAD,doubleSpend);
    doubleSpend.getConfidence().setOverridingTransaction(tx);
  }
}

Fixed version (ground truth):
/** 
 * Handle when a transaction becomes newly active on the best chain, either due to receiving a new block or a re-org making inactive transactions active.
 */
private void processTxFromBestChain(Transaction tx) throws VerificationException {
  boolean isDeadCoinbase=tx.isCoinBase() && dead.containsKey(tx.getHash());
  if (isDeadCoinbase) {
    log.info("String_Node_Str",tx.getHashAsString(),tx.getConfidence().getConfidenceType().name());
    dead.remove(tx.getHash());
  }
  if (inactive.containsKey(tx.getHash())) {
    log.info("String_Node_Str",tx.getHashAsString());
    inactive.remove(tx.getHash());
  }
  updateForSpends(tx,true);
  if (!tx.isEveryOwnedOutputSpent(this)) {
    log.info("String_Node_Str",tx.getHashAsString());
    addWalletTransaction(Pool.UNSPENT,tx);
  }
 else   if (!tx.getValueSentFromMe(this).equals(BigInteger.ZERO)) {
    log.info("String_Node_Str",tx.getHashAsString());
    addWalletTransaction(Pool.SPENT,tx);
  }
 else {
    Transaction doubleSpend=findDoubleSpendAgainstPending(tx);
    if (doubleSpend == null)     throw new IllegalStateException("String_Node_Str");
    log.warn("String_Node_Str",doubleSpend.getHashAsString());
    log.warn("String_Node_Str");
    pending.remove(doubleSpend.getHash());
    addWalletTransaction(Pool.DEAD,doubleSpend);
    doubleSpend.getConfidence().setOverridingTransaction(tx);
  }
}
Program: 85871
Project: 85871
Buggy source:
private synchronized void setDownloadPeer(Peer peer){
  if (chain == null) {
    downloadPeer=peer;
    return;
  }
  if (downloadPeer != null) {
    log.info("String_Node_Str",downloadPeer);
    downloadPeer.setDownloadData(false);
    for (    Wallet wallet : wallets)     downloadPeer.removeWallet(wallet);
  }
  downloadPeer=peer;
  if (downloadPeer != null) {
    log.info("String_Node_Str",downloadPeer);
    downloadPeer.setDownloadData(true);
    downloadPeer.setDownloadParameters(fastCatchupTimeSecs,bloomFilter != null);
    for (    Wallet wallet : wallets)     downloadPeer.addWallet(wallet);
  }
}

Fixed version (ground truth):
private synchronized void setDownloadPeer(Peer peer){
  if (downloadPeer == peer) {
    return;
  }
  if (chain == null) {
    downloadPeer=peer;
    return;
  }
  if (downloadPeer != null) {
    log.info("String_Node_Str",downloadPeer);
    downloadPeer.setDownloadData(false);
    for (    Wallet wallet : wallets)     downloadPeer.removeWallet(wallet);
  }
  downloadPeer=peer;
  if (downloadPeer != null) {
    log.info("String_Node_Str",downloadPeer);
    downloadPeer.setDownloadData(true);
    downloadPeer.setDownloadParameters(fastCatchupTimeSecs,bloomFilter != null);
    for (    Wallet wallet : wallets)     downloadPeer.addWallet(wallet);
  }
}
Program: 85873
Project: 85873
Buggy source:
/** 
 * <p>Link the given wallet to this PeerGroup. This is used for three purposes:</p> <ol> <li>So the wallet receives broadcast transactions.</li> <li>Announcing pending transactions that didn't get into the chain yet to our peers.</li> <li>Set the fast catchup time using   {@link PeerGroup#setFastCatchupTimeSecs(long)}, to optimize chain download.</li> </ol> <p>Note that this should be done before chain download commences because if you add a wallet with keys earlier than the current chain head, the relevant parts of the chain won't be redownloaded for you.</p>
 */
public synchronized void addWallet(Wallet wallet){
  Preconditions.checkNotNull(wallet);
  wallets.add(wallet);
  announcePendingWalletTransactions(Collections.singletonList(wallet),peers);
  wallet.addEventListener(new AbstractWalletEventListener(){
    @Override public void onKeyAdded(    ECKey key){
      recalculateFastCatchupAndFilter();
    }
  }
);
  recalculateFastCatchupAndFilter();
  updateVersionMessageRelayTxesBeforeFilter(getVersionMessage());
}

Fixed version (ground truth):
/** 
 * <p>Link the given wallet to this PeerGroup. This is used for three purposes:</p> <ol> <li>So the wallet receives broadcast transactions.</li> <li>Announcing pending transactions that didn't get into the chain yet to our peers.</li> <li>Set the fast catchup time using   {@link PeerGroup#setFastCatchupTimeSecs(long)}, to optimize chain download.</li> </ol> <p>Note that this should be done before chain download commences because if you add a wallet with keys earlier than the current chain head, the relevant parts of the chain won't be redownloaded for you.</p>
 */
public synchronized void addWallet(Wallet wallet){
  Preconditions.checkNotNull(wallet);
  Preconditions.checkState(!wallets.contains(wallet));
  wallets.add(wallet);
  announcePendingWalletTransactions(Collections.singletonList(wallet),peers);
  wallet.addEventListener(new AbstractWalletEventListener(){
    @Override public void onKeyAdded(    ECKey key){
      recalculateFastCatchupAndFilter();
    }
  }
);
  recalculateFastCatchupAndFilter();
  updateVersionMessageRelayTxesBeforeFilter(getVersionMessage());
}
Program: 85875
Project: 85875
Buggy source:
protected void handlePeerDeath(final Peer peer){
  if (state() != State.RUNNING && state() != State.STARTING)   return;
  checkArgument(!peers.contains(peer));
  final Peer downloadPeer;
  final PeerEventListener downloadListener;
synchronized (this) {
    downloadPeer=this.downloadPeer;
    downloadListener=this.downloadListener;
  }
  if (peer == downloadPeer) {
    log.info("String_Node_Str");
    setDownloadPeer(null);
synchronized (peers) {
      Peer newDownloadPeer=selectDownloadPeer(peers);
      if (newDownloadPeer != null) {
        setDownloadPeer(newDownloadPeer);
        if (downloadListener != null) {
          startBlockChainDownloadFromPeer(newDownloadPeer);
        }
      }
    }
  }
  if (peers.size() + pendingPeers.size() < getMaxConnections()) {
    try {
      connectToAnyPeer();
    }
 catch (    PeerDiscoveryException e) {
      log.error(e.getMessage());
    }
  }
  peer.removeEventListener(getDataListener);
  EventListenerInvoker.invoke(peerEventListeners,new EventListenerInvoker<PeerEventListener>(){
    @Override public void invoke(    PeerEventListener listener){
      listener.onPeerDisconnected(peer,peers.size());
    }
  }
);
}

Fixed version (ground truth):
protected void handlePeerDeath(final Peer peer){
  if (state() != State.RUNNING && state() != State.STARTING)   return;
  checkArgument(!peers.contains(peer));
  final Peer downloadPeer;
  final PeerEventListener downloadListener;
synchronized (this) {
    downloadPeer=this.downloadPeer;
    downloadListener=this.downloadListener;
  }
  if (peer == downloadPeer) {
    log.info("String_Node_Str");
    setDownloadPeer(null);
synchronized (peers) {
      Peer newDownloadPeer=selectDownloadPeer(peers);
      if (newDownloadPeer != null) {
        setDownloadPeer(newDownloadPeer);
        if (downloadListener != null) {
          startBlockChainDownloadFromPeer(newDownloadPeer);
        }
      }
    }
  }
  if (peers.size() + pendingPeers.size() < getMaxConnections()) {
    try {
      connectToAnyPeer();
    }
 catch (    PeerDiscoveryException e) {
      log.error(e.getMessage());
    }
  }
  peer.removeEventListener(getDataListener);
  for (  Wallet wallet : wallets)   peer.removeWallet(wallet);
  EventListenerInvoker.invoke(peerEventListeners,new EventListenerInvoker<PeerEventListener>(){
    @Override public void invoke(    PeerEventListener listener){
      listener.onPeerDisconnected(peer,peers.size());
    }
  }
);
}
Program: 85876
Project: 85876
Buggy source:
private synchronized void setDownloadPeer(Peer peer){
  if (downloadPeer == peer) {
    return;
  }
  if (chain == null) {
    downloadPeer=peer;
    return;
  }
  if (downloadPeer != null) {
    log.info("String_Node_Str",downloadPeer);
    downloadPeer.setDownloadData(false);
    for (    Wallet wallet : wallets)     downloadPeer.removeWallet(wallet);
  }
  downloadPeer=peer;
  if (downloadPeer != null) {
    log.info("String_Node_Str",downloadPeer);
    downloadPeer.setDownloadData(true);
    downloadPeer.setDownloadParameters(fastCatchupTimeSecs,bloomFilter != null);
    for (    Wallet wallet : wallets)     downloadPeer.addWallet(wallet);
  }
}

Fixed version (ground truth):
private synchronized void setDownloadPeer(Peer peer){
  if (downloadPeer == peer) {
    return;
  }
  if (chain == null) {
    downloadPeer=peer;
    return;
  }
  if (downloadPeer != null) {
    log.info("String_Node_Str",downloadPeer);
    downloadPeer.setDownloadData(false);
  }
  downloadPeer=peer;
  if (downloadPeer != null) {
    log.info("String_Node_Str",downloadPeer);
    downloadPeer.setDownloadData(true);
    downloadPeer.setDownloadParameters(fastCatchupTimeSecs,bloomFilter != null);
  }
}
Program: 85877
Project: 85877
Buggy source:
@Test public void receiveTxBroadcast() throws Exception {
  peerGroup.startAndWait();
  peerGroup.addWallet(wallet);
  FakeChannel p1=connectPeer(1);
  FakeChannel p2=connectPeer(2);
  assertEquals(2,peerGroup.numConnectedPeers());
  Set<Peer> tmp=new HashSet<Peer>(peerGroup.getConnectedPeers());
  Set<Peer> expectedPeers=new HashSet<Peer>();
  expectedPeers.add(peerOf(p1));
  expectedPeers.add(peerOf(p2));
  assertEquals(tmp,expectedPeers);
  BigInteger value=Utils.toNanoCoins(1,0);
  Transaction t1=TestUtils.createFakeTx(unitTestParams,value,address);
  InventoryMessage inv=new InventoryMessage(unitTestParams);
  inv.addTransaction(t1);
  inbound(p1,inv);
  assertTrue(outbound(p1) instanceof BloomFilter);
  assertTrue(outbound(p1) instanceof GetDataMessage);
  inbound(p2,inv);
  assertTrue(outbound(p2) instanceof BloomFilter);
  assertNull(outbound(p2));
  inbound(p1,t1);
  assertNull(outbound(p2));
  GetDataMessage getdata=(GetDataMessage)outbound(p1);
  inbound(p1,new NotFoundMessage(unitTestParams,getdata.getItems()));
  assertEquals(value,wallet.getBalance(Wallet.BalanceType.ESTIMATED));
  peerGroup.stop();
}

Fixed version (ground truth):
@Test public void receiveTxBroadcast() throws Exception {
  peerGroup.startAndWait();
  FakeChannel p1=connectPeer(1);
  FakeChannel p2=connectPeer(2);
  assertEquals(2,peerGroup.numConnectedPeers());
  Set<Peer> tmp=new HashSet<Peer>(peerGroup.getConnectedPeers());
  Set<Peer> expectedPeers=new HashSet<Peer>();
  expectedPeers.add(peerOf(p1));
  expectedPeers.add(peerOf(p2));
  assertEquals(tmp,expectedPeers);
  BigInteger value=Utils.toNanoCoins(1,0);
  Transaction t1=TestUtils.createFakeTx(unitTestParams,value,address);
  InventoryMessage inv=new InventoryMessage(unitTestParams);
  inv.addTransaction(t1);
  inbound(p2,inv);
  assertTrue(outbound(p2) instanceof BloomFilter);
  assertTrue(outbound(p2) instanceof GetDataMessage);
  inbound(p1,inv);
  assertTrue(outbound(p1) instanceof BloomFilter);
  assertNull(outbound(p1));
  inbound(p2,t1);
  assertNull(outbound(p1));
  GetDataMessage getdata=(GetDataMessage)outbound(p2);
  assertNotNull(getdata);
  inbound(p2,new NotFoundMessage(unitTestParams,getdata.getItems()));
  assertEquals(value,wallet.getBalance(Wallet.BalanceType.ESTIMATED));
  peerGroup.stopAndWait();
}
Program: 85879
Project: 85879
Buggy source:
/** 
 * Returns the given value in nanocoins as a 0.12 type string. More digits after the decimal place will be used if necessary, but two will always be present.
 */
public static String bitcoinValueToFriendlyString(BigInteger value){
  boolean negative=value.compareTo(BigInteger.ZERO) < 0;
  if (negative)   value=value.negate();
  BigDecimal bd=new BigDecimal(value,8);
  String formatted=bd.toPlainString();
  int toDelete=0;
  for (int i=formatted.length() - 1; i > 1; i--) {
    if (formatted.charAt(i) == '0')     toDelete++;
 else     break;
  }
  return (negative ? "String_Node_Str" : "String_Node_Str") + formatted.substring(0,formatted.length() - toDelete);
}

Fixed version (ground truth):
/** 
 * Returns the given value in nanocoins as a 0.12 type string. More digits after the decimal place will be used if necessary, but two will always be present.
 */
public static String bitcoinValueToFriendlyString(BigInteger value){
  boolean negative=value.compareTo(BigInteger.ZERO) < 0;
  if (negative)   value=value.negate();
  BigDecimal bd=new BigDecimal(value,8);
  String formatted=bd.toPlainString();
  int decimalPoint=formatted.indexOf("String_Node_Str");
  int toDelete=0;
  for (int i=formatted.length() - 1; i > decimalPoint + 2; i--) {
    if (formatted.charAt(i) == '0')     toDelete++;
 else     break;
  }
  return (negative ? "String_Node_Str" : "String_Node_Str") + formatted.substring(0,formatted.length() - toDelete);
}
Program: 85880
Project: 85880
Buggy source:
@Test public void testFormatting(){
  assertEquals("String_Node_Str",bitcoinValueToFriendlyString(toNanoCoins(1,23)));
  assertEquals("String_Node_Str",bitcoinValueToFriendlyString(BigInteger.valueOf(COIN.longValue() / 1000)));
  assertEquals("String_Node_Str",bitcoinValueToFriendlyString(toNanoCoins(1,23).negate()));
}

Fixed version (ground truth):
@Test public void testFormatting(){
  assertEquals("String_Node_Str",bitcoinValueToFriendlyString(toNanoCoins(1,0)));
  assertEquals("String_Node_Str",bitcoinValueToFriendlyString(toNanoCoins(1,23)));
  assertEquals("String_Node_Str",bitcoinValueToFriendlyString(BigInteger.valueOf(COIN.longValue() / 1000)));
  assertEquals("String_Node_Str",bitcoinValueToFriendlyString(toNanoCoins(1,23).negate()));
}
Program: 85881
Project: 85881
Buggy source:
/** 
 * Creates an ECKey given only the private key bytes. This is the same as using the BigInteger constructor, but is more convenient if you are importing a key from elsewhere. The public key will be automatically derived from the private key.
 */
public ECKey(byte[] privKeyBytes,byte[] pubKey){
  this(privKeyBytes == null ? null : new BigInteger(1,privKeyBytes),pubKey);
}

Fixed version (ground truth):
/** 
 * Creates an ECKey given only the private key bytes. This is the same as using the BigInteger constructor, but is more convenient if you are importing a key from elsewhere. If not provided the public key will be automatically derived from the private key.
 */
public ECKey(byte[] privKeyBytes,byte[] pubKey){
  this(privKeyBytes == null ? null : new BigInteger(1,privKeyBytes),pubKey);
}
Program: 85882
Project: 85882
Buggy source:
/** 
 * Returns whether this key is using the compressed form or not. Compressed pubkeys are only 35 bytes, not 64.
 */
public boolean isCompressed(){
  return pub.length == 35;
}

Fixed version (ground truth):
/** 
 * Returns whether this key is using the compressed form or not. Compressed pubkeys are only 33 bytes, not 64.
 */
public boolean isCompressed(){
  return pub.length == 33;
}
Program: 85883
Project: 85883
Buggy source:
/** 
 * Output this ECKey as an ASN.1 encoded private key, as understood by OpenSSL or used by the BitCoin reference implementation in its wallet storage format.
 */
public byte[] toASN1(){
  try {
    ByteArrayOutputStream baos=new ByteArrayOutputStream(400);
    DERSequenceGenerator seq=new DERSequenceGenerator(baos);
    seq.addObject(new ASN1Integer(1));
    seq.addObject(new DEROctetString(priv.toByteArray()));
    seq.addObject(new DERTaggedObject(0,SECNamedCurves.getByName("String_Node_Str").toASN1Primitive()));
    seq.addObject(new DERTaggedObject(1,new DERBitString(getPubKey())));
    seq.close();
    return baos.toByteArray();
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
}

Fixed version (ground truth):
/** 
 * Output this ECKey as an ASN.1 encoded private key, as understood by OpenSSL or used by the Bitcoin reference implementation in its wallet storage format.
 */
public byte[] toASN1(){
  try {
    ByteArrayOutputStream baos=new ByteArrayOutputStream(400);
    DERSequenceGenerator seq=new DERSequenceGenerator(baos);
    seq.addObject(new ASN1Integer(1));
    seq.addObject(new DEROctetString(priv.toByteArray()));
    seq.addObject(new DERTaggedObject(0,SECNamedCurves.getByName("String_Node_Str").toASN1Primitive()));
    seq.addObject(new DERTaggedObject(1,new DERBitString(getPubKey())));
    seq.close();
    return baos.toByteArray();
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
}
Program: 85884
Project: 85884
Buggy source:
@Test public void keyRecovery() throws Exception {
  ECKey key=new ECKey();
  String message="String_Node_Str";
  Sha256Hash hash=Sha256Hash.create(message.getBytes());
  ECKey.ECDSASignature sig=key.sign(hash);
  key=new ECKey(null,key.getPubKey());
  boolean found=false;
  for (int i=0; i < 4; i++) {
    ECKey key2=ECKey.recoverFromSignature(i,sig,hash,false);
    assertNotNull("String_Node_Str",key2);
    if (key.equals(key2)) {
      found=true;
      break;
    }
  }
  assertTrue(found);
}

Fixed version (ground truth):
@Test public void keyRecovery() throws Exception {
  ECKey key=new ECKey();
  String message="String_Node_Str";
  Sha256Hash hash=Sha256Hash.create(message.getBytes());
  ECKey.ECDSASignature sig=key.sign(hash);
  key=new ECKey(null,key.getPubKey());
  boolean found=false;
  for (int i=0; i < 4; i++) {
    ECKey key2=ECKey.recoverFromSignature(i,sig,hash,true);
    if (key.equals(key2)) {
      found=true;
      break;
    }
  }
  assertTrue(found);
}
Program: 85885
Project: 85885
Buggy source:
protected void handlePeerDeath(final Peer peer){
  if (!isRunning())   return;
  checkArgument(!peers.contains(peer));
  final Peer downloadPeer;
  final PeerEventListener downloadListener;
synchronized (this) {
    downloadPeer=this.downloadPeer;
    downloadListener=this.downloadListener;
  }
  if (peer == downloadPeer) {
    log.info("String_Node_Str");
    setDownloadPeer(null);
synchronized (peers) {
      Peer newDownloadPeer=selectDownloadPeer(peers);
      if (newDownloadPeer != null) {
        setDownloadPeer(newDownloadPeer);
        if (downloadListener != null) {
          startBlockChainDownloadFromPeer(newDownloadPeer);
        }
      }
    }
  }
  if (peers.size() + pendingPeers.size() < getMaxConnections()) {
    try {
      connectToAnyPeer();
    }
 catch (    PeerDiscoveryException e) {
      log.error(e.getMessage());
    }
  }
  peer.removeEventListener(getDataListener);
  EventListenerInvoker.invoke(peerEventListeners,new EventListenerInvoker<PeerEventListener>(){
    @Override public void invoke(    PeerEventListener listener){
      listener.onPeerDisconnected(peer,peers.size());
    }
  }
);
}

Fixed version (ground truth):
protected void handlePeerDeath(final Peer peer){
  if (state() != State.RUNNING && state() != State.STARTING)   return;
  checkArgument(!peers.contains(peer));
  final Peer downloadPeer;
  final PeerEventListener downloadListener;
synchronized (this) {
    downloadPeer=this.downloadPeer;
    downloadListener=this.downloadListener;
  }
  if (peer == downloadPeer) {
    log.info("String_Node_Str");
    setDownloadPeer(null);
synchronized (peers) {
      Peer newDownloadPeer=selectDownloadPeer(peers);
      if (newDownloadPeer != null) {
        setDownloadPeer(newDownloadPeer);
        if (downloadListener != null) {
          startBlockChainDownloadFromPeer(newDownloadPeer);
        }
      }
    }
  }
  if (peers.size() + pendingPeers.size() < getMaxConnections()) {
    try {
      connectToAnyPeer();
    }
 catch (    PeerDiscoveryException e) {
      log.error(e.getMessage());
    }
  }
  peer.removeEventListener(getDataListener);
  EventListenerInvoker.invoke(peerEventListeners,new EventListenerInvoker<PeerEventListener>(){
    @Override public void invoke(    PeerEventListener listener){
      listener.onPeerDisconnected(peer,peers.size());
    }
  }
);
}
Program: 85886
Project: 85886
Buggy source:
/** 
 * Catch any exceptions, logging them and then closing the channel. 
 */
@Override public void exceptionCaught(ChannelHandlerContext ctx,ExceptionEvent e) throws Exception {
  String s=address == null ? "String_Node_Str" : address.toString();
  if (e.getCause() instanceof ConnectException || e.getCause() instanceof IOException) {
    log.info(s + "String_Node_Str" + e.getCause().getMessage());
  }
 else {
    log.warn(s + "String_Node_Str",e.getCause());
  }
  e.getChannel().close();
}

Fixed version (ground truth):
/** 
 * Catch any exceptions, logging them and then closing the channel. 
 */
@Override public void exceptionCaught(ChannelHandlerContext ctx,ExceptionEvent e) throws Exception {
  String s;
synchronized (Peer.this) {
    s=address == null ? "String_Node_Str" : address.toString();
  }
  if (e.getCause() instanceof ConnectException || e.getCause() instanceof IOException) {
    log.info(s + "String_Node_Str" + e.getCause().getMessage());
  }
 else {
    log.warn(s + "String_Node_Str",e.getCause());
  }
  e.getChannel().close();
}
Program: 85887
Project: 85887
Buggy source:
/** 
 * @return various version numbers we claim.
 */
public VersionMessage getVersionMessage(){
  return versionMessage;
}

Fixed version (ground truth):
/** 
 * @return various version numbers we claim.
 */
public synchronized VersionMessage getVersionMessage(){
  return versionMessage;
}
Program: 85888
Project: 85888
Buggy source:
/** 
 * When downloading the block chain, the bodies will be skipped for blocks created before the given date. Any transactions relevant to the wallet will therefore not be found, but if you know your wallet has no such transactions it doesn't matter and can save a lot of bandwidth and processing time. Note that the times of blocks isn't known until their headers are available and they are requested in chunks, so some headers may be downloaded twice using this scheme, but this optimization can still be a large win for newly created wallets.
 * @param secondsSinceEpoch Time in seconds since the epoch or 0 to reset to always downloading block bodies.
 */
public void setFastCatchupTime(long secondsSinceEpoch){
  Preconditions.checkNotNull(blockChain);
  if (secondsSinceEpoch == 0) {
    fastCatchupTimeSecs=params.genesisBlock.getTimeSeconds();
    downloadBlockBodies=true;
  }
 else {
    fastCatchupTimeSecs=secondsSinceEpoch;
    if (fastCatchupTimeSecs > blockChain.getChainHead().getHeader().getTimeSeconds()) {
      downloadBlockBodies=false;
    }
  }
}

Fixed version (ground truth):
/** 
 * When downloading the block chain, the bodies will be skipped for blocks created before the given date. Any transactions relevant to the wallet will therefore not be found, but if you know your wallet has no such transactions it doesn't matter and can save a lot of bandwidth and processing time. Note that the times of blocks isn't known until their headers are available and they are requested in chunks, so some headers may be downloaded twice using this scheme, but this optimization can still be a large win for newly created wallets.
 * @param secondsSinceEpoch Time in seconds since the epoch or 0 to reset to always downloading block bodies.
 */
public synchronized void setFastCatchupTime(long secondsSinceEpoch){
  Preconditions.checkNotNull(blockChain);
  if (secondsSinceEpoch == 0) {
    fastCatchupTimeSecs=params.genesisBlock.getTimeSeconds();
    downloadBlockBodies=true;
  }
 else {
    fastCatchupTimeSecs=secondsSinceEpoch;
    if (fastCatchupTimeSecs > blockChain.getChainHead().getHeader().getTimeSeconds()) {
      downloadBlockBodies=false;
    }
  }
}
Program: 85889
Project: 85889
Buggy source:
private void processAlert(AlertMessage m){
  try {
    if (m.isSignatureValid()) {
      log.info("String_Node_Str",toString(),m.getStatusBar());
    }
 else {
      log.warn("String_Node_Str",toString(),m.getStatusBar());
    }
  }
 catch (  Throwable t) {
    log.error("String_Node_Str",t);
  }
}

Fixed version (ground truth):
private synchronized void processAlert(AlertMessage m){
  try {
    if (m.isSignatureValid()) {
      log.info("String_Node_Str",toString(),m.getStatusBar());
    }
 else {
      log.warn("String_Node_Str",toString(),m.getStatusBar());
    }
  }
 catch (  Throwable t) {
    log.error("String_Node_Str",t);
  }
}
Program: 85890
Project: 85890
Buggy source:
private void processPong(Pong m){
  ListIterator<PendingPing> it=pendingPings.listIterator();
  PendingPing ping=null;
  while (it.hasNext()) {
    ping=it.next();
    if (m.getNonce() == ping.nonce) {
      it.remove();
      break;
    }
  }
  if (ping != null)   ping.complete();
}

Fixed version (ground truth):
private synchronized void processPong(Pong m){
  ListIterator<PendingPing> it=pendingPings.listIterator();
  PendingPing ping=null;
  while (it.hasNext()) {
    ping=it.next();
    if (m.getNonce() == ping.nonce) {
      it.remove();
      break;
    }
  }
  if (ping != null)   ping.complete();
}
Program: 85891
Project: 85891
Buggy source:
/** 
 * If set to false, the peer won't try and fetch blocks and transactions it hears about. Normally, only one peer should download missing blocks. Defaults to true.
 */
public void setDownloadData(boolean downloadData){
  this.downloadData=downloadData;
}

Fixed version (ground truth):
/** 
 * If set to false, the peer won't try and fetch blocks and transactions it hears about. Normally, only one peer should download missing blocks. Defaults to true.
 */
public synchronized void setDownloadData(boolean downloadData){
  this.downloadData=downloadData;
}
Program: 85892
Project: 85892
Buggy source:
private void processInv(InventoryMessage inv) throws IOException {
  List<InventoryItem> items=inv.getItems();
  List<InventoryItem> transactions=new LinkedList<InventoryItem>();
  List<InventoryItem> blocks=new LinkedList<InventoryItem>();
  for (  InventoryItem item : items) {
switch (item.type) {
case Transaction:
      transactions.add(item);
    break;
case Block:
  blocks.add(item);
break;
default :
throw new IllegalStateException("String_Node_Str" + item.type);
}
}
if (transactions.size() == 0 && blocks.size() == 1) {
if (downloadData) {
if (!blockChain.isOrphan(blocks.get(0).hash)) {
blocksAnnounced++;
}
}
 else {
blocksAnnounced++;
}
}
GetDataMessage getdata=new GetDataMessage(params);
Iterator<InventoryItem> it=transactions.iterator();
while (it.hasNext()) {
InventoryItem item=it.next();
if (memoryPool == null) {
if (downloadData) {
getdata.addItem(item);
}
}
 else {
if (memoryPool.maybeWasSeen(item.hash)) {
it.remove();
}
 else {
log.debug("String_Node_Str",address,item.hash);
getdata.addItem(item);
}
memoryPool.seen(item.hash,this.getAddress());
}
}
if (blocks.size() > 0 && downloadData && blockChain != null) {
for (InventoryItem item : blocks) {
if (blockChain.isOrphan(item.hash)) {
blockChainDownload(blockChain.getOrphanRoot(item.hash).getHash());
}
 else {
if (!pendingBlockDownloads.contains(item.hash)) {
getdata.addItem(item);
pendingBlockDownloads.add(item.hash);
}
}
}
}
if (!getdata.getItems().isEmpty()) {
sendMessage(getdata);
}
}

Fixed version (ground truth):
private synchronized void processInv(InventoryMessage inv) throws IOException {
  List<InventoryItem> items=inv.getItems();
  List<InventoryItem> transactions=new LinkedList<InventoryItem>();
  List<InventoryItem> blocks=new LinkedList<InventoryItem>();
  for (  InventoryItem item : items) {
switch (item.type) {
case Transaction:
      transactions.add(item);
    break;
case Block:
  blocks.add(item);
break;
default :
throw new IllegalStateException("String_Node_Str" + item.type);
}
}
if (transactions.size() == 0 && blocks.size() == 1) {
if (downloadData) {
if (!blockChain.isOrphan(blocks.get(0).hash)) {
blocksAnnounced++;
}
}
 else {
blocksAnnounced++;
}
}
GetDataMessage getdata=new GetDataMessage(params);
Iterator<InventoryItem> it=transactions.iterator();
while (it.hasNext()) {
InventoryItem item=it.next();
if (memoryPool == null) {
if (downloadData) {
getdata.addItem(item);
}
}
 else {
if (memoryPool.maybeWasSeen(item.hash)) {
it.remove();
}
 else {
log.debug("String_Node_Str",address,item.hash);
getdata.addItem(item);
}
memoryPool.seen(item.hash,this.getAddress());
}
}
if (blocks.size() > 0 && downloadData && blockChain != null) {
for (InventoryItem item : blocks) {
if (blockChain.isOrphan(item.hash)) {
blockChainDownload(blockChain.getOrphanRoot(item.hash).getHash());
}
 else {
if (!pendingBlockDownloads.contains(item.hash)) {
getdata.addItem(item);
pendingBlockDownloads.add(item.hash);
}
}
}
}
if (!getdata.getItems().isEmpty()) {
sendMessage(getdata);
}
}
Program: 85893
Project: 85893
Buggy source:
private void blockChainDownload(Sha256Hash toHash) throws IOException {
  List<Sha256Hash> blockLocator=new ArrayList<Sha256Hash>(51);
  BlockStore store=blockChain.getBlockStore();
  StoredBlock chainHead=blockChain.getChainHead();
  Sha256Hash chainHeadHash=chainHead.getHeader().getHash();
  if (Objects.equal(lastGetBlocksBegin,chainHeadHash) && Objects.equal(lastGetBlocksEnd,toHash)) {
    log.info("String_Node_Str",toHash.toString());
    return;
  }
  log.info("String_Node_Str",new Object[]{toString(),toHash.toString(),chainHead.getHeader().getHashAsString()});
  StoredBlock cursor=chainHead;
  for (int i=100; cursor != null && i > 0; i--) {
    blockLocator.add(cursor.getHeader().getHash());
    try {
      cursor=cursor.getPrev(store);
    }
 catch (    BlockStoreException e) {
      log.error("String_Node_Str");
      throw new RuntimeException(e);
    }
  }
  if (cursor != null) {
    blockLocator.add(params.genesisBlock.getHash());
  }
  lastGetBlocksBegin=chainHeadHash;
  lastGetBlocksEnd=toHash;
  if (downloadBlockBodies) {
    GetBlocksMessage message=new GetBlocksMessage(params,blockLocator,toHash);
    sendMessage(message);
  }
 else {
    GetHeadersMessage message=new GetHeadersMessage(params,blockLocator,toHash);
    sendMessage(message);
  }
}

Fixed version (ground truth):
private synchronized void blockChainDownload(Sha256Hash toHash) throws IOException {
  List<Sha256Hash> blockLocator=new ArrayList<Sha256Hash>(51);
  BlockStore store=blockChain.getBlockStore();
  StoredBlock chainHead=blockChain.getChainHead();
  Sha256Hash chainHeadHash=chainHead.getHeader().getHash();
  if (Objects.equal(lastGetBlocksBegin,chainHeadHash) && Objects.equal(lastGetBlocksEnd,toHash)) {
    log.info("String_Node_Str",toHash.toString());
    return;
  }
  log.info("String_Node_Str",new Object[]{toString(),toHash.toString(),chainHead.getHeader().getHashAsString()});
  StoredBlock cursor=chainHead;
  for (int i=100; cursor != null && i > 0; i--) {
    blockLocator.add(cursor.getHeader().getHash());
    try {
      cursor=cursor.getPrev(store);
    }
 catch (    BlockStoreException e) {
      log.error("String_Node_Str");
      throw new RuntimeException(e);
    }
  }
  if (cursor != null) {
    blockLocator.add(params.genesisBlock.getHash());
  }
  lastGetBlocksBegin=chainHeadHash;
  lastGetBlocksEnd=toHash;
  if (downloadBlockBodies) {
    GetBlocksMessage message=new GetBlocksMessage(params,blockLocator,toHash);
    sendMessage(message);
  }
 else {
    GetHeadersMessage message=new GetHeadersMessage(params,blockLocator,toHash);
    sendMessage(message);
  }
}
Program: 85894
Project: 85894
Buggy source:
/** 
 * Returns the difference between our best chain height and the peers, which can either be positive if we are behind the peer, or negative if the peer is ahead of us.
 */
public int getPeerBlockHeightDifference(){
  int chainHeight=(int)getBestHeight();
  Preconditions.checkState(params.allowEmptyPeerChains || chainHeight > 0,"String_Node_Str",chainHeight);
  return chainHeight - blockChain.getChainHead().getHeight();
}

Fixed version (ground truth):
/** 
 * Returns the difference between our best chain height and the peers, which can either be positive if we are behind the peer, or negative if the peer is ahead of us.
 */
public synchronized int getPeerBlockHeightDifference(){
  int chainHeight=(int)getBestHeight();
  Preconditions.checkState(params.allowEmptyPeerChains || chainHeight > 0,"String_Node_Str",chainHeight);
  return chainHeight - blockChain.getChainHead().getHeight();
}
Program: 85895
Project: 85895
Buggy source:
/** 
 * @return various version numbers claimed by peer.
 */
public VersionMessage getPeerVersionMessage(){
  return peerVersionMessage;
}

Fixed version (ground truth):
/** 
 * @return various version numbers claimed by peer.
 */
public synchronized VersionMessage getPeerVersionMessage(){
  return peerVersionMessage;
}