Program: 100924
Project: 100924
Buggy source:
/** 
 * Stores blocks, transactions, and input/output nodes to the database. Blocks will be given a relationship of "succeeds" to the previous categorized block to the database. Transactions will be given a relationship of "from" to its owner Block. Input/Output nodes (called Money nodes) will either be given "sent" or "received" relationships based upon what they represent. This function maintains a local json repository by downloading it directly from the API. Then, it persists the json blocks to the datastore from these local json files.
 * @author John
 */
public void downloadBlockChain(boolean doValidate){
  final int LATEST_DISK_BLOCK_INDEX;
  final int LATEST_INTERNET_BLOCK_INDEX;
  int lastDatabaseBlockIndex;
  LatestBlock latestInternetBlock=Fetcher.GetLatest();
  LATEST_INTERNET_BLOCK_INDEX=latestInternetBlock.getBlock_index();
  Collection<File> files=Fetcher.getFolderContents("String_Node_Str");
  ArrayList<Integer> fileNames=new ArrayList<Integer>();
  for (  File file : files) {
    if (file.getName().endsWith("String_Node_Str"))     fileNames.add(Integer.parseInt(file.getName().split("String_Node_Str")[0]));
  }
  Collections.sort(fileNames);
  LATEST_DISK_BLOCK_INDEX=fileNames.get(fileNames.size() - 1);
  downloadChain(LATEST_DISK_BLOCK_INDEX,latestInternetBlock);
  Node latestDatabaseBlock=getLatestLocalBlockNode();
  if (latestDatabaseBlock.hasProperty("String_Node_Str"))   lastDatabaseBlockIndex=(Integer)latestDatabaseBlock.getProperty("String_Node_Str");
 else   lastDatabaseBlockIndex=0;
  if (doValidate) {
    if (isBlockchainComplete()) {
      LOG.info("String_Node_Str");
    }
 else {
      LOG.severe("String_Node_Str");
      return;
    }
  }
 else {
    LOG.info("String_Node_Str");
    BlockType currentBlock=null;
    RestNode currentBlockNode=null;
    while (lastDatabaseBlockIndex < LATEST_INTERNET_BLOCK_INDEX) {
      try {
        for (int i=lastDatabaseBlockIndex; i < LATEST_INTERNET_BLOCK_INDEX; i++) {
          if (FileUtils.getFile((i + 1) + "String_Node_Str").exists()) {
            currentBlock=Fetcher.GetBlock(FileUtils.getFile((i + 1) + "String_Node_Str")).getBlockType();
            break;
          }
        }
      }
 catch (      FetcherException e) {
        LOG.log(Level.SEVERE,"String_Node_Str" + e.getMessage() + "String_Node_Str",e);
        return;
      }
      LOG.info("String_Node_Str" + currentBlock.getBlock_index());
      Map<String,Object> blockProps=new HashMap<String,Object>();
      blockProps.put("String_Node_Str",currentBlock.getHash());
      blockProps.put("String_Node_Str",currentBlock.getVer());
      blockProps.put("String_Node_Str",currentBlock.getPrev_block());
      blockProps.put("String_Node_Str",currentBlock.getMrkl_root());
      blockProps.put("String_Node_Str",currentBlock.getTime());
      blockProps.put("String_Node_Str",currentBlock.getBits());
      blockProps.put("String_Node_Str",currentBlock.getNonce());
      blockProps.put("String_Node_Str",currentBlock.getN_tx());
      blockProps.put("String_Node_Str",currentBlock.getSize());
      blockProps.put("String_Node_Str",currentBlock.getBlock_index());
      blockProps.put("String_Node_Str",currentBlock.getMain_chain());
      blockProps.put("String_Node_Str",currentBlock.getHeight());
      blockProps.put("String_Node_Str",currentBlock.getReceived_time());
      blockProps.put("String_Node_Str",currentBlock.getRelayed_by());
      currentBlockNode=restApi.createNode(blockProps);
      if (latestDatabaseBlock.hasProperty("String_Node_Str") && !((String)currentBlockNode.getProperty("String_Node_Str")).contains((String)latestDatabaseBlock.getProperty("String_Node_Str"))) {
        TraversalDescription td=new TraversalDescriptionImpl();
        td=td.depthFirst().relationships(BitcoinRelationships.succeeds);
        Iterable<Node> nodeTraversal=td.traverse(latestDatabaseBlock).nodes();
        for (Iterator<Node> iter=nodeTraversal.iterator(); iter.hasNext(); ) {
          Node blockNode=iter.next();
          if (blockNode.hasProperty("String_Node_Str") && ((String)blockNode.getProperty("String_Node_Str")).contains(((String)currentBlockNode.getProperty("String_Node_Str")))) {
            restApi.createRelationship(currentBlockNode,blockNode,BitcoinRelationships.succeeds,null);
          }
        }
      }
 else {
        restApi.createRelationship(currentBlockNode,latestDatabaseBlock,BitcoinRelationships.succeeds,null);
      }
      Map<String,Object> tranProps;
      TransactionType tran;
      RestNode tranNode=null;
      Map<String,Object> fromRelation;
      for (Iterator<TransactionType> tranIter=currentBlock.getAscTx().iterator(); tranIter.hasNext(); ) {
        tranProps=new HashMap<String,Object>();
        tran=tranIter.next();
        tranProps.put("String_Node_Str",tran.getHash());
        tranProps.put("String_Node_Str",tran.getVer());
        tranProps.put("String_Node_Str",tran.getVin_sz());
        tranProps.put("String_Node_Str",tran.getVout_sz());
        tranProps.put("String_Node_Str",tran.getSize());
        tranProps.put("String_Node_Str",tran.getRelayed_by());
        tranProps.put("String_Node_Str",tran.getTx_index());
        tranNode=restApi.createNode(tranProps);
        fromRelation=new HashMap<String,Object>();
        fromRelation.put("String_Node_Str",currentBlock.getHash());
        restApi.createRelationship(tranNode,currentBlockNode,BitcoinRelationships.from,fromRelation);
        transactionsIndex.add(tranNode,"String_Node_Str",tran.getTx_index());
        Map<String,Object> moneyProps;
        RestNode outNode=null;
        OutputType output;
        Map<String,Object> sentRelation;
        int n=0;
        for (Iterator<OutputType> outputIter=tran.getOut().iterator(); outputIter.hasNext(); ) {
          moneyProps=new HashMap<String,Object>();
          output=outputIter.next();
          moneyProps.put("String_Node_Str",output.getType());
          moneyProps.put("String_Node_Str",output.getAddr());
          moneyProps.put("String_Node_Str",output.getValue());
          moneyProps.put("String_Node_Str",n);
          outNode=restApi.createNode(moneyProps);
          sentRelation=new HashMap<String,Object>();
          sentRelation.put("String_Node_Str",output.getAddr());
          sentRelation.put("String_Node_Str",n);
          restApi.createRelationship(tranNode,outNode,BitcoinRelationships.sent,sentRelation);
          n++;
        }
        Map<String,Object> receivedRelation;
        PrevOut prevOut;
        for (Iterator<InputType> inputIter=tran.getInputs().iterator(); inputIter.hasNext(); ) {
          moneyProps=new HashMap<String,Object>();
          prevOut=inputIter.next().getPrev_out();
          if (prevOut == null)           continue;
          moneyProps.put("String_Node_Str",prevOut.getType());
          moneyProps.put("String_Node_Str",prevOut.getAddr());
          moneyProps.put("String_Node_Str",prevOut.getValue());
          moneyProps.put("String_Node_Str",prevOut.getN());
          Node transactionNode=transactionsIndex.query("String_Node_Str",prevOut.getTx_index()).getSingle();
          if (transactionNode != null) {
            Iterable<Relationship> moneyNodeRelationships=transactionNode.getRelationships(BitcoinRelationships.sent,Direction.OUTGOING);
            for (Iterator<Relationship> moneyIter=moneyNodeRelationships.iterator(); moneyIter.hasNext(); ) {
              Node[] moneyNodes=moneyIter.next().getNodes();
              for (int i=0; i < moneyNodes.length; i++) {
                if (moneyNodes[i].hasProperty("String_Node_Str") && moneyNodes[i].hasProperty("String_Node_Str") && ((String)moneyNodes[i].getProperty("String_Node_Str")).contains(prevOut.getAddr())&& ((Integer)moneyNodes[i].getProperty("String_Node_Str") == prevOut.getN())) {
                  receivedRelation=new HashMap<String,Object>();
                  receivedRelation.put("String_Node_Str",prevOut.getTx_index());
                  restApi.createRelationship(moneyNodes[i],tranNode,BitcoinRelationships.received,receivedRelation);
                  break;
                }
              }
            }
          }
        }
      }
      lastDatabaseBlockIndex=currentBlock.getBlock_index();
      latestDatabaseBlock=currentBlockNode;
    }
  }
}

Fixed version (ground truth):
/** 
 * Stores blocks, transactions, and input/output nodes to the database. Blocks will be given a relationship of "succeeds" to the previous categorized block to the database. Transactions will be given a relationship of "from" to its owner Block. Input/Output nodes (called Money nodes) will either be given "sent" or "received" relationships based upon what they represent. This function maintains a local json repository by downloading it directly from the API. Then, it persists the json blocks to the datastore from these local json files.
 * @author John
 */
public void downloadBlockChain(boolean doValidate){
  final int LATEST_DISK_BLOCK_INDEX;
  final int LATEST_INTERNET_BLOCK_INDEX;
  int lastDatabaseBlockIndex;
  LatestBlock latestInternetBlock=Fetcher.GetLatest();
  LATEST_INTERNET_BLOCK_INDEX=latestInternetBlock.getBlock_index();
  Collection<File> files=Fetcher.getFolderContents("String_Node_Str");
  ArrayList<Integer> fileNames=new ArrayList<Integer>();
  for (  File file : files) {
    if (file.getName().endsWith("String_Node_Str"))     fileNames.add(Integer.parseInt(file.getName().split("String_Node_Str")[0]));
  }
  Collections.sort(fileNames);
  LATEST_DISK_BLOCK_INDEX=fileNames.get(fileNames.size() - 1);
  downloadChain(LATEST_DISK_BLOCK_INDEX,latestInternetBlock);
  Node latestDatabaseBlock=getLatestLocalBlockNode();
  if (latestDatabaseBlock.hasProperty("String_Node_Str"))   lastDatabaseBlockIndex=(Integer)latestDatabaseBlock.getProperty("String_Node_Str");
 else   lastDatabaseBlockIndex=0;
  if (doValidate) {
    if (isBlockchainComplete()) {
      LOG.info("String_Node_Str");
    }
 else {
      LOG.severe("String_Node_Str");
      return;
    }
  }
  LOG.info("String_Node_Str");
  BlockType currentBlock=null;
  RestNode currentBlockNode=null;
  while (lastDatabaseBlockIndex < LATEST_INTERNET_BLOCK_INDEX) {
    try {
      for (int i=lastDatabaseBlockIndex; i < LATEST_INTERNET_BLOCK_INDEX; i++) {
        if (FileUtils.getFile((i + 1) + "String_Node_Str").exists()) {
          currentBlock=Fetcher.GetBlock(FileUtils.getFile((i + 1) + "String_Node_Str")).getBlockType();
          break;
        }
      }
    }
 catch (    FetcherException e) {
      LOG.log(Level.SEVERE,"String_Node_Str" + e.getMessage() + "String_Node_Str",e);
      return;
    }
    LOG.info("String_Node_Str" + currentBlock.getBlock_index());
    Map<String,Object> blockProps=new HashMap<String,Object>();
    blockProps.put("String_Node_Str",currentBlock.getHash());
    blockProps.put("String_Node_Str",currentBlock.getVer());
    blockProps.put("String_Node_Str",currentBlock.getPrev_block());
    blockProps.put("String_Node_Str",currentBlock.getMrkl_root());
    blockProps.put("String_Node_Str",currentBlock.getTime());
    blockProps.put("String_Node_Str",currentBlock.getBits());
    blockProps.put("String_Node_Str",currentBlock.getNonce());
    blockProps.put("String_Node_Str",currentBlock.getN_tx());
    blockProps.put("String_Node_Str",currentBlock.getSize());
    blockProps.put("String_Node_Str",currentBlock.getBlock_index());
    blockProps.put("String_Node_Str",currentBlock.getMain_chain());
    blockProps.put("String_Node_Str",currentBlock.getHeight());
    blockProps.put("String_Node_Str",currentBlock.getReceived_time());
    blockProps.put("String_Node_Str",currentBlock.getRelayed_by());
    currentBlockNode=restApi.createNode(blockProps);
    if (latestDatabaseBlock.hasProperty("String_Node_Str") && !((String)currentBlockNode.getProperty("String_Node_Str")).contains((String)latestDatabaseBlock.getProperty("String_Node_Str"))) {
      TraversalDescription td=new TraversalDescriptionImpl();
      td=td.depthFirst().relationships(BitcoinRelationships.succeeds);
      Iterable<Node> nodeTraversal=td.traverse(latestDatabaseBlock).nodes();
      for (Iterator<Node> iter=nodeTraversal.iterator(); iter.hasNext(); ) {
        Node blockNode=iter.next();
        if (blockNode.hasProperty("String_Node_Str") && ((String)blockNode.getProperty("String_Node_Str")).contains(((String)currentBlockNode.getProperty("String_Node_Str")))) {
          restApi.createRelationship(currentBlockNode,blockNode,BitcoinRelationships.succeeds,null);
        }
      }
    }
 else {
      restApi.createRelationship(currentBlockNode,latestDatabaseBlock,BitcoinRelationships.succeeds,null);
    }
    Map<String,Object> tranProps;
    TransactionType tran;
    RestNode tranNode=null;
    Map<String,Object> fromRelation;
    for (Iterator<TransactionType> tranIter=currentBlock.getAscTx().iterator(); tranIter.hasNext(); ) {
      tranProps=new HashMap<String,Object>();
      tran=tranIter.next();
      tranProps.put("String_Node_Str",tran.getHash());
      tranProps.put("String_Node_Str",tran.getVer());
      tranProps.put("String_Node_Str",tran.getVin_sz());
      tranProps.put("String_Node_Str",tran.getVout_sz());
      tranProps.put("String_Node_Str",tran.getSize());
      tranProps.put("String_Node_Str",tran.getRelayed_by());
      tranProps.put("String_Node_Str",tran.getTx_index());
      tranNode=restApi.createNode(tranProps);
      fromRelation=new HashMap<String,Object>();
      fromRelation.put("String_Node_Str",currentBlock.getHash());
      restApi.createRelationship(tranNode,currentBlockNode,BitcoinRelationships.from,fromRelation);
      transactionsIndex.add(tranNode,"String_Node_Str",tran.getTx_index());
      Map<String,Object> moneyProps;
      RestNode outNode=null;
      OutputType output;
      Map<String,Object> sentRelation;
      int n=0;
      for (Iterator<OutputType> outputIter=tran.getOut().iterator(); outputIter.hasNext(); ) {
        moneyProps=new HashMap<String,Object>();
        output=outputIter.next();
        moneyProps.put("String_Node_Str",output.getType());
        moneyProps.put("String_Node_Str",output.getAddr());
        moneyProps.put("String_Node_Str",output.getValue());
        moneyProps.put("String_Node_Str",n);
        outNode=restApi.createNode(moneyProps);
        sentRelation=new HashMap<String,Object>();
        sentRelation.put("String_Node_Str",output.getAddr());
        sentRelation.put("String_Node_Str",n);
        restApi.createRelationship(tranNode,outNode,BitcoinRelationships.sent,sentRelation);
        n++;
      }
      Map<String,Object> receivedRelation;
      PrevOut prevOut;
      for (Iterator<InputType> inputIter=tran.getInputs().iterator(); inputIter.hasNext(); ) {
        moneyProps=new HashMap<String,Object>();
        prevOut=inputIter.next().getPrev_out();
        if (prevOut == null)         continue;
        moneyProps.put("String_Node_Str",prevOut.getType());
        moneyProps.put("String_Node_Str",prevOut.getAddr());
        moneyProps.put("String_Node_Str",prevOut.getValue());
        moneyProps.put("String_Node_Str",prevOut.getN());
        Node transactionNode=transactionsIndex.query("String_Node_Str",prevOut.getTx_index()).getSingle();
        if (transactionNode != null) {
          Iterable<Relationship> moneyNodeRelationships=transactionNode.getRelationships(BitcoinRelationships.sent,Direction.OUTGOING);
          for (Iterator<Relationship> moneyIter=moneyNodeRelationships.iterator(); moneyIter.hasNext(); ) {
            Node[] moneyNodes=moneyIter.next().getNodes();
            for (int i=0; i < moneyNodes.length; i++) {
              if (moneyNodes[i].hasProperty("String_Node_Str") && moneyNodes[i].hasProperty("String_Node_Str") && ((String)moneyNodes[i].getProperty("String_Node_Str")).contains(prevOut.getAddr())&& ((Integer)moneyNodes[i].getProperty("String_Node_Str") == prevOut.getN())) {
                receivedRelation=new HashMap<String,Object>();
                receivedRelation.put("String_Node_Str",prevOut.getTx_index());
                restApi.createRelationship(moneyNodes[i],tranNode,BitcoinRelationships.received,receivedRelation);
                break;
              }
            }
          }
        }
      }
    }
    lastDatabaseBlockIndex=currentBlock.getBlock_index();
    latestDatabaseBlock=currentBlockNode;
  }
}