Program: 56747
Project: 56747
Buggy source:
@Override public void run(){
  LOG.info(String.format("String_Node_Str",config.getStreamName()));
  DateTime lastShardCapacityRefreshTime=new DateTime(System.currentTimeMillis());
  StreamMetrics streamMaxCapacity;
  try {
    streamMaxCapacity=getStreamMaxCapacity();
  }
 catch (  Exception e) {
    this.exception=e;
    return;
  }
  int cwSampleDuration=Math.max(config.getScaleUp().getScaleAfterMins(),config.getScaleDown().getScaleAfterMins());
  List<GetMetricStatisticsRequest> cwRequests=getCloudwatchRequests(config.getScaleOnOperation());
  try {
    ScalingOperationReport report=null;
    do {
      DateTime now=new DateTime(System.currentTimeMillis());
      DateTime metricEndTime=new DateTime(System.currentTimeMillis());
      DateTime metricStartTime=metricEndTime.minusMinutes(cwSampleDuration);
      Map<StreamMetric,Map<Datapoint,Double>> metricsMap=new HashMap<StreamMetric,Map<Datapoint,Double>>();
      for (      StreamMetric m : StreamMetric.values()) {
        metricsMap.put(m,new HashMap<Datapoint,Double>());
      }
      for (      GetMetricStatisticsRequest req : cwRequests) {
        double sampleMetric=0D;
        req.withStartTime(metricStartTime.toDate()).withEndTime(metricEndTime.toDate());
        LOG.debug(String.format("String_Node_Str",cwSampleDuration,req.getMetricName()));
        GetMetricStatisticsResult cloudWatchMetrics=cloudWatchClient.getMetricStatistics(req);
        for (        Datapoint d : cloudWatchMetrics.getDatapoints()) {
          StreamMetric metric=StreamMetric.fromUnit(d.getUnit());
          Map<Datapoint,Double> metrics=metricsMap.get(metric);
          if (metrics.containsKey(d)) {
            sampleMetric=metrics.get(d);
          }
 else {
            sampleMetric=0d;
          }
          sampleMetric+=(d.getSum() / CLOUDWATCH_PERIOD);
          metrics.put(d,sampleMetric);
        }
      }
      report=processCloudwatchMetrics(metricsMap,streamMaxCapacity,cwSampleDuration,now);
      if (report != null) {
        streamMaxCapacity=getStreamMaxCapacity();
        lastShardCapacityRefreshTime=now;
      }
      if (report != null) {
        if (this.config.getScalingOperationReportListener() != null) {
          this.config.getScalingOperationReportListener().onReport(report);
        }
        LOG.info(report.toString());
        report=null;
      }
      if (now.minusMinutes(this.config.getRefreshShardsNumberAfterMin()).isAfter(lastShardCapacityRefreshTime)) {
        streamMaxCapacity=getStreamMaxCapacity();
        lastShardCapacityRefreshTime=now;
      }
      try {
        LOG.debug("String_Node_Str");
        Thread.sleep(TIMEOUT_SECONDS * 1000);
      }
 catch (      InterruptedException e) {
        LOG.error(e);
        break;
      }
    }
 while (keepRunning=true);
    LOG.info(String.format("String_Node_Str",this.config.getStreamName(),this.config.getRegion()));
  }
 catch (  Exception e) {
    this.exception=e;
  }
}

Fixed version (ground truth):
@Override public void run(){
  LOG.info(String.format("String_Node_Str",config.getStreamName()));
  DateTime lastShardCapacityRefreshTime=new DateTime(System.currentTimeMillis());
  StreamMetrics streamMaxCapacity;
  try {
    streamMaxCapacity=getStreamMaxCapacity();
  }
 catch (  Exception e) {
    this.exception=e;
    return;
  }
  int cwSampleDuration=Math.max(config.getScaleUp().getScaleAfterMins(),config.getScaleDown().getScaleAfterMins());
  List<GetMetricStatisticsRequest> cwRequests=getCloudwatchRequests(config.getScaleOnOperation());
  try {
    ScalingOperationReport report=null;
    do {
      DateTime now=new DateTime(System.currentTimeMillis());
      DateTime metricEndTime=new DateTime(System.currentTimeMillis());
      DateTime metricStartTime=metricEndTime.minusMinutes(cwSampleDuration);
      Map<StreamMetric,Map<Datapoint,Double>> metricsMap=new HashMap<StreamMetric,Map<Datapoint,Double>>();
      for (      StreamMetric m : StreamMetric.values()) {
        metricsMap.put(m,new HashMap<Datapoint,Double>());
      }
      for (      GetMetricStatisticsRequest req : cwRequests) {
        double sampleMetric=0D;
        req.withStartTime(metricStartTime.toDate()).withEndTime(metricEndTime.toDate());
        LOG.debug(String.format("String_Node_Str",cwSampleDuration,req.getMetricName()));
        GetMetricStatisticsResult cloudWatchMetrics=cloudWatchClient.getMetricStatistics(req);
        for (        Datapoint d : cloudWatchMetrics.getDatapoints()) {
          StreamMetric metric=StreamMetric.fromUnit(d.getUnit());
          Map<Datapoint,Double> metrics=metricsMap.get(metric);
          if (metrics.containsKey(d)) {
            sampleMetric=metrics.get(d);
          }
 else {
            sampleMetric=0d;
          }
          sampleMetric+=(d.getSum() / CLOUDWATCH_PERIOD);
          metrics.put(d,sampleMetric);
        }
      }
      report=processCloudwatchMetrics(metricsMap,streamMaxCapacity,cwSampleDuration,now);
      if (report != null) {
        streamMaxCapacity=getStreamMaxCapacity();
        lastShardCapacityRefreshTime=now;
      }
      if (report != null) {
        if (this.config.getScalingOperationReportListener() != null) {
          this.config.getScalingOperationReportListener().onReport(report);
        }
        LOG.info(report.toString());
        report=null;
      }
      if (now.minusMinutes(this.config.getRefreshShardsNumberAfterMin()).isAfter(lastShardCapacityRefreshTime)) {
        streamMaxCapacity=getStreamMaxCapacity();
        lastShardCapacityRefreshTime=now;
      }
      try {
        LOG.debug("String_Node_Str");
        Thread.sleep(TIMEOUT_SECONDS * 1000);
      }
 catch (      InterruptedException e) {
        LOG.error(e);
        break;
      }
    }
 while (keepRunning);
    LOG.info(String.format("String_Node_Str",this.config.getStreamName(),this.config.getRegion()));
  }
 catch (  Exception e) {
    this.exception=e;
  }
}