Program: 17546
Project: 17546
Buggy source:
public void catchUpdates(final boolean ask){
  mSwipeUpdater.setRefreshing(true);
  final Thread updateThread=new Thread(new Runnable(){
    @Override public void run(){
      try {
        final URL recoveryUrl=new URL(Const.RECOVERY_SUMS_URL);
        URLConnection recoveryCon=recoveryUrl.openConnection();
        long recoveryListSize=recoveryCon.getContentLength();
        long recoveryListLocalSize=Const.RecoveryCollectionFile.length();
        if (recoveryListSize > 0) {
          isRecoveryListUpToDate=recoveryListLocalSize == recoveryListSize;
        }
        final URL kernelUrl=new URL(Const.KERNEL_SUMS_URL);
        URLConnection kernelCon=kernelUrl.openConnection();
        long kernelListSize=kernelCon.getContentLength();
        long kernelListLocalSize=Const.KernelCollectionFile.length();
        if (kernelListSize > 0) {
          isKernelListUpToDate=kernelListLocalSize == kernelListSize;
        }
      }
 catch (      IOException e) {
        mActivity.runOnUiThread(new Runnable(){
          @Override public void run(){
            Toast.makeText(mContext,R.string.check_connection,Toast.LENGTH_SHORT).show();
          }
        }
);
        mActivity.addError(Const.RASHR_TAG,e,false);
      }
      mActivity.runOnUiThread(new Runnable(){
        @Override public void run(){
          if (!isRecoveryListUpToDate || !isKernelListUpToDate) {
            final int img_count=mDevice.getStockRecoveryVersions().size() + mDevice.getCwmRecoveryVersions().size() + mDevice.getTwrpRecoveryVersions().size()+ mDevice.getPhilzRecoveryVersions().size()+ mDevice.getStockKernelVersions().size();
            final URL recoveryURL;
            final URL kernelURL;
            try {
              recoveryURL=new URL(Const.RECOVERY_SUMS_URL);
              kernelURL=new URL(Const.KERNEL_SUMS_URL);
            }
 catch (            MalformedURLException e) {
              return;
            }
            final DownloadDialog RecoveryUpdater=new DownloadDialog(mContext,recoveryURL,Const.RecoveryCollectionFile);
            RecoveryUpdater.setOverrideFile(true);
            RecoveryUpdater.setOnDownloadListener(new DownloadDialog.OnDownloadListener(){
              @Override public void success(              File file){
                mDevice.loadRecoveryList();
                isRecoveryListUpToDate=true;
                final DownloadDialog KernelUpdater=new DownloadDialog(mContext,kernelURL,Const.KernelCollectionFile);
                KernelUpdater.setOverrideFile(true);
                KernelUpdater.setOnDownloadListener(new DownloadDialog.OnDownloadListener(){
                  @Override public void success(                  File file){
                    mDevice.loadKernelList();
                    isKernelListUpToDate=true;
                    final int new_img_count=(mDevice.getStockRecoveryVersions().size() + mDevice.getCwmRecoveryVersions().size() + mDevice.getTwrpRecoveryVersions().size()+ mDevice.getPhilzRecoveryVersions().size()+ mDevice.getStockKernelVersions().size()) - img_count;
                    mActivity.runOnUiThread(new Runnable(){
                      @Override public void run(){
                        if (isAdded()) {
                          Toast.makeText(mActivity,String.format(getString(R.string.new_imgs_loaded),new_img_count),Toast.LENGTH_SHORT).show();
                        }
                        mSwipeUpdater.setRefreshing(false);
                      }
                    }
);
                  }
                  @Override public void failed(                  final Exception e){
                    Toast.makeText(mActivity,e.getMessage(),Toast.LENGTH_SHORT).show();
                    mSwipeUpdater.setRefreshing(false);
                  }
                }
);
                KernelUpdater.execute();
              }
              @Override public void failed(              final Exception e){
                Toast.makeText(mActivity,e.getMessage(),Toast.LENGTH_SHORT).show();
                mSwipeUpdater.setRefreshing(false);
              }
            }
);
            mActivity.runOnUiThread(new Runnable(){
              @Override public void run(){
                if (ask) {
                  AlertDialog.Builder updateDialog=new AlertDialog.Builder(mContext);
                  updateDialog.setTitle(R.string.update_available).setMessage(R.string.lists_outdated).setPositiveButton(R.string.update,new DialogInterface.OnClickListener(){
                    @Override public void onClick(                    DialogInterface dialog,                    int which){
                      Toast.makeText(mActivity,R.string.refresh_list,Toast.LENGTH_SHORT).show();
                      RecoveryUpdater.execute();
                    }
                  }
).setNegativeButton(android.R.string.cancel,new DialogInterface.OnClickListener(){
                    @Override public void onClick(                    DialogInterface dialog,                    int which){
                    }
                  }
).show();
                }
 else {
                  Toast.makeText(mActivity,R.string.refresh_list,Toast.LENGTH_SHORT).show();
                  RecoveryUpdater.execute();
                }
              }
            }
);
          }
 else {
            mActivity.runOnUiThread(new Runnable(){
              @Override public void run(){
                if (!Common.getBooleanPref(mContext,Const.PREF_NAME,Const.PREF_KEY_HIDE_UPDATE_HINTS)) {
                  Toast.makeText(mContext,R.string.uptodate,Toast.LENGTH_SHORT).show();
                }
                mSwipeUpdater.setRefreshing(false);
              }
            }
);
          }
        }
      }
);
    }
  }
);
  updateThread.start();
}

Fixed version (ground truth):
public void catchUpdates(final boolean ask){
  mSwipeUpdater.setRefreshing(true);
  final Thread updateThread=new Thread(new Runnable(){
    @Override public void run(){
      try {
        final URL recoveryUrl=new URL(Const.RECOVERY_SUMS_URL);
        URLConnection recoveryCon=recoveryUrl.openConnection();
        long recoveryListSize=recoveryCon.getContentLength();
        long recoveryListLocalSize=Const.RecoveryCollectionFile.length();
        if (recoveryListSize > 0) {
          isRecoveryListUpToDate=recoveryListLocalSize == recoveryListSize;
        }
        final URL kernelUrl=new URL(Const.KERNEL_SUMS_URL);
        URLConnection kernelCon=kernelUrl.openConnection();
        long kernelListSize=kernelCon.getContentLength();
        long kernelListLocalSize=Const.KernelCollectionFile.length();
        if (kernelListSize > 0) {
          isKernelListUpToDate=kernelListLocalSize == kernelListSize;
        }
      }
 catch (      IOException e) {
        mActivity.runOnUiThread(new Runnable(){
          @Override public void run(){
            Toast.makeText(mContext,R.string.check_connection,Toast.LENGTH_SHORT).show();
          }
        }
);
        mActivity.addError(Const.RASHR_TAG,e,false);
      }
      mActivity.runOnUiThread(new Runnable(){
        @Override public void run(){
          if (!isRecoveryListUpToDate || !isKernelListUpToDate) {
            final int img_count=mDevice.getStockRecoveryVersions().size() + mDevice.getCwmRecoveryVersions().size() + mDevice.getTwrpRecoveryVersions().size()+ mDevice.getPhilzRecoveryVersions().size()+ mDevice.getStockKernelVersions().size();
            final URL recoveryURL;
            final URL kernelURL;
            try {
              recoveryURL=new URL(Const.RECOVERY_SUMS_URL);
              kernelURL=new URL(Const.KERNEL_SUMS_URL);
            }
 catch (            MalformedURLException e) {
              return;
            }
            Downloader downloader=new Downloader(recoveryURL,Const.RecoveryCollectionFile);
            final DownloadDialog RecoveryUpdater=new DownloadDialog(mContext,downloader);
            downloader.setOverrideFile(true);
            RecoveryUpdater.setOnDownloadListener(new DownloadDialog.OnDownloadListener(){
              @Override public void onSuccess(              File file){
                mDevice.loadRecoveryList();
                isRecoveryListUpToDate=true;
                Downloader downloader=new Downloader(kernelURL,Const.KernelCollectionFile);
                final DownloadDialog KernelUpdater=new DownloadDialog(mContext,downloader);
                downloader.setOverrideFile(true);
                KernelUpdater.setOnDownloadListener(new DownloadDialog.OnDownloadListener(){
                  @Override public void onSuccess(                  File file){
                    mDevice.loadKernelList();
                    isKernelListUpToDate=true;
                    final int new_img_count=(mDevice.getStockRecoveryVersions().size() + mDevice.getCwmRecoveryVersions().size() + mDevice.getTwrpRecoveryVersions().size()+ mDevice.getPhilzRecoveryVersions().size()+ mDevice.getStockKernelVersions().size()) - img_count;
                    mActivity.runOnUiThread(new Runnable(){
                      @Override public void run(){
                        if (isAdded()) {
                          Toast.makeText(mActivity,String.format(getString(R.string.new_imgs_loaded),new_img_count),Toast.LENGTH_SHORT).show();
                        }
                        mSwipeUpdater.setRefreshing(false);
                      }
                    }
);
                  }
                  @Override public void onFail(                  final Exception e){
                    Toast.makeText(mActivity,e.getMessage(),Toast.LENGTH_SHORT).show();
                    mSwipeUpdater.setRefreshing(false);
                  }
                }
);
                KernelUpdater.download();
              }
              @Override public void onFail(              final Exception e){
                Toast.makeText(mActivity,e.getMessage(),Toast.LENGTH_SHORT).show();
                mSwipeUpdater.setRefreshing(false);
              }
            }
);
            mActivity.runOnUiThread(new Runnable(){
              @Override public void run(){
                if (ask) {
                  AlertDialog.Builder updateDialog=new AlertDialog.Builder(mContext);
                  updateDialog.setTitle(R.string.update_available).setMessage(R.string.lists_outdated).setPositiveButton(R.string.update,new DialogInterface.OnClickListener(){
                    @Override public void onClick(                    DialogInterface dialog,                    int which){
                      Toast.makeText(mActivity,R.string.refresh_list,Toast.LENGTH_SHORT).show();
                      RecoveryUpdater.download();
                    }
                  }
).setNegativeButton(android.R.string.cancel,new DialogInterface.OnClickListener(){
                    @Override public void onClick(                    DialogInterface dialog,                    int which){
                    }
                  }
).show();
                }
 else {
                  Toast.makeText(mActivity,R.string.refresh_list,Toast.LENGTH_SHORT).show();
                  RecoveryUpdater.download();
                }
              }
            }
);
          }
 else {
            mActivity.runOnUiThread(new Runnable(){
              @Override public void run(){
                if (!Common.getBooleanPref(mContext,Const.PREF_NAME,Const.PREF_KEY_HIDE_UPDATE_HINTS)) {
                  Toast.makeText(mContext,R.string.uptodate,Toast.LENGTH_SHORT).show();
                }
                mSwipeUpdater.setRefreshing(false);
              }
            }
);
          }
        }
      }
);
    }
  }
);
  updateThread.start();
}