Program: 94357
Project: 94357
Buggy source:
public static void initialCalibration(int bg1,int bg2,Context context){
  CalibrationRequest.clearAll();
  List<Calibration> pastCalibrations=Calibration.allForSensor();
  if (pastCalibrations != null) {
    for (    Calibration calibration : pastCalibrations) {
      calibration.slope_confidence=0;
      calibration.sensor_confidence=0;
      calibration.save();
    }
  }
  Calibration higherCalibration=new Calibration();
  Calibration lowerCalibration=new Calibration();
  Sensor sensor=Sensor.currentSensor();
  List<BgReading> bgReadings=BgReading.latest_by_size(2);
  BgReading bgReading1=bgReadings.get(0);
  BgReading bgReading2=bgReadings.get(1);
  BgReading highBgReading;
  BgReading lowBgReading;
  int higher_bg;
  int lower_bg;
  if (bg1 > bg2) {
    higher_bg=bg1;
    lower_bg=bg2;
  }
 else   if (bg2 > bg1) {
    higher_bg=bg2;
    lower_bg=bg1;
  }
 else {
    higher_bg=bg1;
    lower_bg=bg1 - 1;
  }
  if (bgReading1.raw_data > bgReading2.raw_data) {
    highBgReading=bgReading1;
    lowBgReading=bgReading2;
  }
 else   if (bgReading2.raw_data > bgReading1.raw_data) {
    highBgReading=bgReading2;
    lowBgReading=bgReading1;
  }
 else {
    highBgReading=bgReading2;
    lowBgReading=bgReading1;
  }
  int lowerAdjust=0;
  if (highBgReading.age_adjusted_raw_value == lowBgReading.age_adjusted_raw_value) {
    lowerAdjust=2;
  }
  higherCalibration.bg=higher_bg;
  higherCalibration.slope=0;
  higherCalibration.intercept=higher_bg;
  higherCalibration.sensor=sensor;
  higherCalibration.estimate_raw_at_time_of_calibration=highBgReading.age_adjusted_raw_value;
  higherCalibration.raw_value=highBgReading.raw_data;
  higherCalibration.save();
  lowerCalibration.bg=lower_bg;
  lowerCalibration.slope=0;
  lowerCalibration.intercept=lower_bg;
  lowerCalibration.sensor=sensor;
  lowerCalibration.estimate_raw_at_time_of_calibration=lowBgReading.age_adjusted_raw_value - lowerAdjust;
  lowerCalibration.raw_value=lowBgReading.raw_data;
  lowerCalibration.save();
  highBgReading.calculated_value=higher_bg;
  highBgReading.calibration_flag=true;
  highBgReading.save();
  higherCalibration.bgReading=highBgReading;
  higherCalibration.save();
  lowBgReading.calculated_value=lower_bg;
  lowBgReading.calibration_flag=true;
  lowBgReading.save();
  lowerCalibration.bgReading=lowBgReading;
  lowerCalibration.save();
  highBgReading.find_new_curve();
  highBgReading.find_new_raw_curve();
  lowBgReading.find_new_curve();
  lowBgReading.find_new_raw_curve();
  List<Calibration> calibrations=new ArrayList<Calibration>();
  calibrations.add(lowerCalibration);
  calibrations.add(higherCalibration);
  for (  Calibration calibration : calibrations) {
    BgReading bgReading=calibration.bgReading;
    calibration.timestamp=new Date().getTime();
    calibration.sensor_uuid=sensor.uuid;
    calibration.slope_confidence=.5;
    calibration.raw_timestamp=bgReading.timestamp;
    calibration.distance_from_estimate=0;
    calibration.sensor_confidence=((-0.0018 * calibration.bg * calibration.bg) + (0.6657 * calibration.bg) + 36.7505) / 100;
    calibration.sensor_age_at_time_of_estimation=calibration.timestamp - sensor.started_at;
    calibration.uuid=UUID.randomUUID().toString();
    calibration.save();
    calculate_w_l_s();
    adjustRecentBgReadings();
    CalibrationSendQueue.addToQueue(calibration);
    Gson gson=new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class,new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
    Log.w("String_Node_Str",calibration.toS());
    CalibrationRequest.createOffset(calibration.bg,40);
  }
  Notifications.notificationSetter(context);
}

Fixed version (ground truth):
public static void initialCalibration(int bg1,int bg2,Context context){
  CalibrationRequest.clearAll();
  List<Calibration> pastCalibrations=Calibration.allForSensor();
  if (pastCalibrations != null) {
    for (    Calibration calibration : pastCalibrations) {
      calibration.slope_confidence=0;
      calibration.sensor_confidence=0;
      calibration.save();
    }
  }
  Calibration higherCalibration=new Calibration();
  Calibration lowerCalibration=new Calibration();
  Sensor sensor=Sensor.currentSensor();
  List<BgReading> bgReadings=BgReading.latest_by_size(2);
  BgReading bgReading1=bgReadings.get(0);
  BgReading bgReading2=bgReadings.get(1);
  BgReading highBgReading;
  BgReading lowBgReading;
  int higher_bg;
  int lower_bg;
  if (bg1 > bg2) {
    higher_bg=bg1;
    lower_bg=bg2;
  }
 else   if (bg2 > bg1) {
    higher_bg=bg2;
    lower_bg=bg1;
  }
 else {
    higher_bg=bg1;
    lower_bg=bg1 - 1;
  }
  if (bgReading1.raw_data > bgReading2.raw_data) {
    highBgReading=bgReading1;
    lowBgReading=bgReading2;
  }
 else   if (bgReading2.raw_data > bgReading1.raw_data) {
    highBgReading=bgReading2;
    lowBgReading=bgReading1;
  }
 else {
    highBgReading=bgReading2;
    lowBgReading=bgReading1;
  }
  int lowerAdjust=0;
  if (highBgReading.age_adjusted_raw_value == lowBgReading.age_adjusted_raw_value) {
    lowerAdjust=2;
  }
  higherCalibration.bg=higher_bg;
  higherCalibration.slope=0;
  higherCalibration.intercept=higher_bg;
  higherCalibration.sensor=sensor;
  higherCalibration.estimate_raw_at_time_of_calibration=highBgReading.age_adjusted_raw_value;
  higherCalibration.raw_value=highBgReading.raw_data;
  higherCalibration.save();
  lowerCalibration.bg=lower_bg;
  lowerCalibration.slope=0;
  lowerCalibration.intercept=lower_bg;
  lowerCalibration.sensor=sensor;
  lowerCalibration.estimate_raw_at_time_of_calibration=lowBgReading.age_adjusted_raw_value - lowerAdjust;
  lowerCalibration.raw_value=lowBgReading.raw_data;
  lowerCalibration.save();
  highBgReading.calculated_value=higher_bg;
  highBgReading.calibration_flag=true;
  highBgReading.calibration=higherCalibration;
  highBgReading.save();
  higherCalibration.bgReading=highBgReading;
  higherCalibration.save();
  lowBgReading.calculated_value=lower_bg;
  lowBgReading.calibration_flag=true;
  lowBgReading.calibration=lowerCalibration;
  lowBgReading.save();
  lowerCalibration.bgReading=lowBgReading;
  lowerCalibration.save();
  highBgReading.find_new_curve();
  highBgReading.find_new_raw_curve();
  lowBgReading.find_new_curve();
  lowBgReading.find_new_raw_curve();
  List<Calibration> calibrations=new ArrayList<Calibration>();
  calibrations.add(lowerCalibration);
  calibrations.add(higherCalibration);
  for (  Calibration calibration : calibrations) {
    BgReading bgReading=calibration.bgReading;
    calibration.timestamp=new Date().getTime();
    calibration.sensor_uuid=sensor.uuid;
    calibration.slope_confidence=.5;
    calibration.raw_timestamp=bgReading.timestamp;
    calibration.distance_from_estimate=0;
    calibration.sensor_confidence=((-0.0018 * calibration.bg * calibration.bg) + (0.6657 * calibration.bg) + 36.7505) / 100;
    calibration.sensor_age_at_time_of_estimation=calibration.timestamp - sensor.started_at;
    calibration.uuid=UUID.randomUUID().toString();
    calibration.save();
    calculate_w_l_s();
    adjustRecentBgReadings();
    CalibrationSendQueue.addToQueue(calibration);
    Gson gson=new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class,new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
    Log.w("String_Node_Str",calibration.toS());
    CalibrationRequest.createOffset(calibration.bg,45);
  }
  Notifications.notificationSetter(context);
}