Program: 170807
Project: 170807
Buggy source:
private void updateStats(boolean force){
  try {
    this_mon.enter();
    long current_time=SystemTime.getCurrentTime() / 1000;
    if (current_time < lastUptime) {
      lastUptime=current_time;
      return;
    }
    long current_total_d_received=gm_stats.getTotalDataBytesReceived();
    long current_total_p_received=gm_stats.getTotalProtocolBytesReceived();
    long current_total_d_sent=gm_stats.getTotalDataBytesSent();
    long current_total_p_sent=gm_stats.getTotalProtocolBytesSent();
    long current_total_received=current_total_d_received + current_total_p_received;
    long current_total_sent=current_total_d_sent + current_total_p_sent;
    totalDownloaded+=current_total_received - lastDownloaded;
    lastDownloaded=current_total_received;
    if (totalDownloaded < 0)     totalDownloaded=0;
    totalUploaded+=current_total_sent - lastUploaded;
    lastUploaded=current_total_sent;
    if (totalUploaded < 0)     totalUploaded=0;
    totalDataDownloaded+=current_total_d_received - lastDataDownloaded;
    lastDataDownloaded=current_total_d_received;
    if (totalDataDownloaded < 0)     totalDataDownloaded=0;
    totalProtocolDownloaded+=current_total_p_received - lastProtocolDownloaded;
    lastProtocolDownloaded=current_total_p_received;
    if (totalProtocolDownloaded < 0)     totalProtocolDownloaded=0;
    totalDataUploaded+=current_total_d_sent - lastDataUploaded;
    lastDataUploaded=current_total_d_sent;
    if (totalDataUploaded < 0)     totalDataUploaded=0;
    totalProtocolUploaded+=current_total_p_sent - lastProtocolUploaded;
    lastProtocolUploaded=current_total_p_sent;
    if (totalProtocolUploaded < 0)     totalProtocolUploaded=0;
    if (dhts == null) {
      try {
        PluginManager pm=core.getPluginManager();
        if (pm.isInitialized()) {
          PluginInterface dht_pi=pm.getPluginInterfaceByClass(DHTPlugin.class);
          if (dht_pi == null) {
            dhts=new DHT[0];
          }
 else {
            DHTPlugin plugin=(DHTPlugin)dht_pi.getPlugin();
            if (!plugin.isInitialising()) {
              if (plugin.isEnabled()) {
                dhts=((DHTPlugin)dht_pi.getPlugin()).getDHTs();
              }
 else {
                dhts=new DHT[0];
              }
            }
          }
        }
      }
 catch (      Throwable e) {
        dhts=new DHT[0];
      }
    }
    long current_total_dht_up=0;
    long current_total_dht_down=0;
    if (dhts != null) {
      for (      DHT dht : dhts) {
        DHTTransportStats stats=dht.getTransport().getStats();
        current_total_dht_up+=stats.getBytesSent();
        current_total_dht_down+=stats.getBytesReceived();
      }
    }
    totalDHTUploaded+=current_total_dht_up - lastDHTUploaded;
    lastDHTUploaded=current_total_dht_up;
    if (totalDHTUploaded < 0)     totalDHTUploaded=0;
    totalDHTDownloaded+=current_total_dht_down - lastDHTDownloaded;
    lastDHTDownloaded=current_total_dht_down;
    if (totalDHTDownloaded < 0)     totalDHTDownloaded=0;
    long delta=current_time - lastUptime;
    if (delta > 100 || delta < 0) {
      lastUptime=current_time;
      return;
    }
    if (totalUptime > TEN_YEARS) {
      totalUptime=0;
    }
    if (totalUptime < 0)     totalUptime=0;
    totalUptime+=delta;
    lastUptime=current_time;
    lastSnapshot=new long[]{totalProtocolUploaded,totalDataUploaded,totalProtocolDownloaded,totalDataDownloaded,totalDHTUploaded,totalDHTDownloaded,current_total_p_sent,current_total_d_sent,current_total_p_received,current_total_d_received,current_total_dht_up,current_total_dht_down};
    HashMap overallMap=new HashMap();
    overallMap.put("String_Node_Str",new Long(totalDownloaded));
    overallMap.put("String_Node_Str",new Long(totalUploaded));
    overallMap.put("String_Node_Str",new Long(totalUptime));
    overallMap.put("String_Node_Str",new Long(markTime));
    overallMap.put("String_Node_Str",new Long(markTotalDownloaded));
    overallMap.put("String_Node_Str",new Long(markTotalUploaded));
    overallMap.put("String_Node_Str",new Long(markTotalUptime));
    overallMap.put("String_Node_Str",new Long(totalDHTDownloaded));
    overallMap.put("String_Node_Str",new Long(totalDHTUploaded));
    overallMap.put("String_Node_Str",new Long(totalProtocolUploaded));
    overallMap.put("String_Node_Str",new Long(totalDataUploaded));
    overallMap.put("String_Node_Str",new Long(totalProtocolDownloaded));
    overallMap.put("String_Node_Str",new Long(totalDataDownloaded));
    Map map=new HashMap();
    map.put("String_Node_Str",overallMap);
    tick_count++;
    if (force || tick_count % SAVE_TICKS == 0) {
      save(map);
    }
  }
  finally {
    this_mon.exit();
  }
}

Fixed version (ground truth):
private void updateStats(boolean force){
  try {
    this_mon.enter();
    long current_time=SystemTime.getCurrentTime() / 1000;
    if (current_time < lastUptime) {
      lastUptime=current_time;
      return;
    }
    long current_total_d_received=gm_stats.getTotalDataBytesReceived();
    long current_total_p_received=gm_stats.getTotalProtocolBytesReceived();
    long current_total_d_sent=gm_stats.getTotalDataBytesSent();
    long current_total_p_sent=gm_stats.getTotalProtocolBytesSent();
    long current_total_received=current_total_d_received + current_total_p_received;
    long current_total_sent=current_total_d_sent + current_total_p_sent;
    totalDownloaded+=current_total_received - lastDownloaded;
    lastDownloaded=current_total_received;
    if (totalDownloaded < 0)     totalDownloaded=0;
    totalUploaded+=current_total_sent - lastUploaded;
    lastUploaded=current_total_sent;
    if (totalUploaded < 0)     totalUploaded=0;
    totalDataDownloaded+=current_total_d_received - lastDataDownloaded;
    lastDataDownloaded=current_total_d_received;
    if (totalDataDownloaded < 0)     totalDataDownloaded=0;
    totalProtocolDownloaded+=current_total_p_received - lastProtocolDownloaded;
    lastProtocolDownloaded=current_total_p_received;
    if (totalProtocolDownloaded < 0)     totalProtocolDownloaded=0;
    totalDataUploaded+=current_total_d_sent - lastDataUploaded;
    lastDataUploaded=current_total_d_sent;
    if (totalDataUploaded < 0)     totalDataUploaded=0;
    totalProtocolUploaded+=current_total_p_sent - lastProtocolUploaded;
    lastProtocolUploaded=current_total_p_sent;
    if (totalProtocolUploaded < 0)     totalProtocolUploaded=0;
    if (dhts == null) {
      try {
        PluginManager pm=core.getPluginManager();
        if (pm.isInitialized()) {
          PluginInterface dht_pi=pm.getPluginInterfaceByClass(DHTPlugin.class);
          if (dht_pi == null) {
            dhts=new DHT[0];
          }
 else {
            DHTPlugin plugin=(DHTPlugin)dht_pi.getPlugin();
            if (!plugin.isInitialising()) {
              if (plugin.isEnabled()) {
                dhts=((DHTPlugin)dht_pi.getPlugin()).getDHTs();
              }
 else {
                dhts=new DHT[0];
              }
            }
          }
        }
      }
 catch (      Throwable e) {
        dhts=new DHT[0];
      }
    }
    long current_total_dht_up=0;
    long current_total_dht_down=0;
    if (dhts != null) {
      for (      DHT dht : dhts) {
        DHTTransportStats stats=dht.getTransport().getStats();
        current_total_dht_up+=stats.getBytesSent();
        current_total_dht_down+=stats.getBytesReceived();
      }
    }
    totalDHTUploaded+=current_total_dht_up - lastDHTUploaded;
    lastDHTUploaded=current_total_dht_up;
    if (totalDHTUploaded < 0)     totalDHTUploaded=0;
    totalDHTDownloaded+=current_total_dht_down - lastDHTDownloaded;
    lastDHTDownloaded=current_total_dht_down;
    if (totalDHTDownloaded < 0)     totalDHTDownloaded=0;
    long delta=current_time - lastUptime;
    if (delta > 100 || delta < 0) {
      lastUptime=current_time;
      return;
    }
    if (totalUptime < 0)     totalUptime=0;
    totalUptime+=delta;
    lastUptime=current_time;
    lastSnapshot=new long[]{totalProtocolUploaded,totalDataUploaded,totalProtocolDownloaded,totalDataDownloaded,totalDHTUploaded,totalDHTDownloaded,current_total_p_sent,current_total_d_sent,current_total_p_received,current_total_d_received,current_total_dht_up,current_total_dht_down};
    HashMap overallMap=new HashMap();
    overallMap.put("String_Node_Str",new Long(totalDownloaded));
    overallMap.put("String_Node_Str",new Long(totalUploaded));
    overallMap.put("String_Node_Str",new Long(totalUptime));
    overallMap.put("String_Node_Str",new Long(markTime));
    overallMap.put("String_Node_Str",new Long(markTotalDownloaded));
    overallMap.put("String_Node_Str",new Long(markTotalUploaded));
    overallMap.put("String_Node_Str",new Long(markTotalUptime));
    overallMap.put("String_Node_Str",new Long(totalDHTDownloaded));
    overallMap.put("String_Node_Str",new Long(totalDHTUploaded));
    overallMap.put("String_Node_Str",new Long(totalProtocolUploaded));
    overallMap.put("String_Node_Str",new Long(totalDataUploaded));
    overallMap.put("String_Node_Str",new Long(totalProtocolDownloaded));
    overallMap.put("String_Node_Str",new Long(totalDataDownloaded));
    Map map=new HashMap();
    map.put("String_Node_Str",overallMap);
    tick_count++;
    if (force || tick_count % SAVE_TICKS == 0) {
      save(map);
    }
  }
  finally {
    this_mon.exit();
  }
}