Program: 169207
Project: 169207
Buggy source:
@Override protected DownloadResults doDownload(){
  DownloadStatus status=DownloadStatus.SUCCESS;
  try {
    transport.open();
  }
 catch (  IOException e) {
    status=DownloadStatus.IO_ERROR;
  }
  ReadData readData=new ReadData(transport);
  List<EGVRecord> recentRecords=new ArrayList<>();
  List<MeterRecord> meterRecords=new ArrayList<>();
  List<SensorRecord> sensorRecords=new ArrayList<>();
  List<CalRecord> calRecords=new ArrayList<>();
  long displayTime=0;
  long timeSinceLastRecord=0;
  int batLevel=100;
  if (status == DownloadStatus.SUCCESS) {
    try {
      recentRecords=readData.getRecentEGVsPages(numOfPages);
      meterRecords=readData.getRecentMeterRecords();
      if (preferences.isSensorUploadEnabled()) {
        sensorRecords=readData.getRecentSensorRecords(numOfPages);
      }
      if (preferences.isCalibrationUploadEnabled()) {
        calRecords=readData.getRecentCalRecords();
      }
      displayTime=readData.readDisplayTime().getTime();
      timeSinceLastRecord=readData.getTimeSinceEGVRecord(recentRecords.get(recentRecords.size() - 1));
      batLevel=100;
    }
 catch (    IOException e) {
      status=DownloadStatus.IO_ERROR;
    }
catch (    InvalidRecordLengthException e) {
      status=DownloadStatus.APPLICATION_ERROR;
    }
 finally {
      try {
        transport.close();
      }
 catch (      IOException e) {
        status=DownloadStatus.IO_ERROR;
      }
    }
  }
  List<CookieMonsterG4SGV> cookieMonsterG4SGVs=EGVRecord.toProtobufList(recentRecords);
  List<CookieMonsterG4Cal> cookieMonsterG4Cals=CalRecord.toProtobufList(calRecords);
  List<CookieMonsterG4Meter> cookieMonsterG4Meters=MeterRecord.toProtobufList(meterRecords);
  List<CookieMonsterG4Sensor> cookieMonsterG4Sensors=SensorRecord.toProtobufList(sensorRecords);
  CookieMonsterDownload.Builder downloadBuilder=new CookieMonsterDownload.Builder();
  downloadBuilder.sgv(cookieMonsterG4SGVs).cal(cookieMonsterG4Cals).sensor(cookieMonsterG4Sensors).meter(cookieMonsterG4Meters).download_timestamp(new Date().toString()).download_status(status).uploader_battery(uploaderDevice.getBatteryLevel()).receiver_battery(batLevel).units(GlucoseUnit.MGDL);
  long nextUploadTime=standardMinutes(5).minus(standardSeconds(timeSinceLastRecord)).getMillis();
  JSONArray array=new JSONArray();
  for (  EGVRecord recentRecord : recentRecords) {
    try {
      array.put(recentRecord.toJSON());
    }
 catch (    JSONException e) {
      e.printStackTrace();
    }
  }
  return new DownloadResults(downloadBuilder.build(),nextUploadTime,array,displayTime);
}

Fixed version (ground truth):
@Override protected DownloadResults doDownload(){
  DownloadStatus status=DownloadStatus.SUCCESS;
  try {
    transport.open();
  }
 catch (  IOException e) {
    status=DownloadStatus.IO_ERROR;
  }
  ReadData readData=new ReadData(transport);
  List<EGVRecord> recentRecords=new ArrayList<>();
  List<MeterRecord> meterRecords=new ArrayList<>();
  List<SensorRecord> sensorRecords=new ArrayList<>();
  List<CalRecord> calRecords=new ArrayList<>();
  long displayTime=0;
  long timeSinceLastRecord=0;
  int batLevel=100;
  if (status == DownloadStatus.SUCCESS) {
    try {
      recentRecords=readData.getRecentEGVsPages(numOfPages);
      meterRecords=readData.getRecentMeterRecords();
      if (preferences.isSensorUploadEnabled()) {
        sensorRecords=readData.getRecentSensorRecords(numOfPages);
      }
      if (preferences.isCalibrationUploadEnabled()) {
        calRecords=readData.getRecentCalRecords();
      }
      if (recentRecords.size() == 0) {
        status=DownloadStatus.NO_DATA;
      }
      displayTime=readData.readDisplayTime().getTime();
      if (status == DownloadStatus.SUCCESS) {
        timeSinceLastRecord=readData.getTimeSinceEGVRecord(recentRecords.get(recentRecords.size() - 1));
      }
      batLevel=100;
    }
 catch (    IOException e) {
      status=DownloadStatus.IO_ERROR;
    }
catch (    InvalidRecordLengthException e) {
      status=DownloadStatus.APPLICATION_ERROR;
    }
 finally {
      try {
        transport.close();
      }
 catch (      IOException e) {
        status=DownloadStatus.IO_ERROR;
      }
    }
  }
  List<CookieMonsterG4SGV> cookieMonsterG4SGVs=EGVRecord.toProtobufList(recentRecords);
  List<CookieMonsterG4Cal> cookieMonsterG4Cals=CalRecord.toProtobufList(calRecords);
  List<CookieMonsterG4Meter> cookieMonsterG4Meters=MeterRecord.toProtobufList(meterRecords);
  List<CookieMonsterG4Sensor> cookieMonsterG4Sensors=SensorRecord.toProtobufList(sensorRecords);
  CookieMonsterDownload.Builder downloadBuilder=new CookieMonsterDownload.Builder();
  downloadBuilder.sgv(cookieMonsterG4SGVs).cal(cookieMonsterG4Cals).sensor(cookieMonsterG4Sensors).meter(cookieMonsterG4Meters).download_timestamp(new Date().toString()).download_status(status).uploader_battery(uploaderDevice.getBatteryLevel()).receiver_battery(batLevel).units(GlucoseUnit.MGDL);
  long nextUploadTime=standardMinutes(5).minus(standardSeconds(timeSinceLastRecord)).getMillis();
  JSONArray array=new JSONArray();
  for (  EGVRecord recentRecord : recentRecords) {
    try {
      array.put(recentRecord.toJSON());
    }
 catch (    JSONException e) {
      e.printStackTrace();
    }
  }
  return new DownloadResults(downloadBuilder.build(),nextUploadTime,array,displayTime);
}