Program: 187124
Project: 187124
Buggy source:
private void downloadWithTor(boolean useTor,Uri uri,String title,String desc,File targetFile){
  initNotificationManager();
  String nTag=indexItem.getExpansionId();
  int nId=0;
  if (fileName.contains(scal.io.liger.Constants.MAIN)) {
    nId=Integer.parseInt(indexItem.getExpansionFileVersion());
  }
 else   if (fileName.contains(scal.io.liger.Constants.PATCH)) {
    nId=Integer.parseInt(indexItem.getPatchFileVersion());
  }
  OkHttpClient httpClient=new OkHttpClient();
  if (useTor) {
    if (checkTor(context)) {
      Timber.d("String_Node_Str" + scal.io.liger.Constants.TOR_PROXY_HOST + "String_Node_Str"+ scal.io.liger.Constants.TOR_PROXY_PORT);
      SocketAddress torSocket=new InetSocketAddress(scal.io.liger.Constants.TOR_PROXY_HOST,scal.io.liger.Constants.TOR_PROXY_PORT);
      Proxy torProxy=new Proxy(Proxy.Type.HTTP,torSocket);
      httpClient.setProxy(torProxy);
    }
 else {
      Timber.e("String_Node_Str");
      if (context instanceof Activity) {
        Utils.toastOnUiThread((Activity)context,"String_Node_Str",true);
      }
      StorymakerQueueManager.checkQueueFinished(context,targetFile.getName());
      return;
    }
  }
  httpClient.setRetryOnConnectionFailure(false);
  httpClient.setConnectTimeout(3000,TimeUnit.MILLISECONDS);
  String actualFileName=targetFile.getName().substring(0,targetFile.getName().lastIndexOf("String_Node_Str"));
  Timber.d("String_Node_Str" + uri.toString());
  try {
    Request request=new Request.Builder().url(uri.toString()).build();
    File partFile=new File(targetFile.getPath().replace("String_Node_Str","String_Node_Str"));
    if (partFile.exists()) {
      long partBytes=partFile.length();
      Timber.d("String_Node_Str" + partFile.getPath() + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ Long.toString(partBytes)+ "String_Node_Str");
      request=new Request.Builder().url(uri.toString()).addHeader("String_Node_Str","String_Node_Str" + Long.toString(partBytes) + "String_Node_Str").build();
    }
 else {
      Timber.d("String_Node_Str" + partFile.getPath() + "String_Node_Str");
    }
    Response response=httpClient.newCall(request).execute();
    int statusCode=response.code();
    if ((statusCode == 200) || (statusCode == 206)) {
      Timber.d("String_Node_Str" + statusCode);
      Date startTime=new Date();
      long queueId=0 - startTime.getTime();
      StorymakerQueueManager.addToQueue(context,queueId,targetFile.getName(),queueDao);
      targetFile.getParentFile().mkdirs();
      Timber.d("String_Node_Str");
      BufferedInputStream responseInput=new BufferedInputStream(response.body().byteStream());
      try {
        FileOutputStream targetOutput=new FileOutputStream(targetFile);
        byte[] buf=new byte[1024];
        int i;
        int oldPercent=0;
        long thisTime;
        long lastTime=-1;
        int lastPercent=0;
        while ((i=responseInput.read(buf)) > 0) {
          int nPercent=StorymakerDownloadHelper.getDownloadPercent(context,fileName,installedDao);
          thisTime=System.currentTimeMillis();
          if (oldPercent == nPercent) {
          }
 else {
            if (nPercent % 10 == 0 && nPercent != lastPercent) {
              if (lastTime == -1 || (thisTime - lastTime) > 1000) {
                lastPercent=nPercent;
                oldPercent=nPercent;
                lastTime=thisTime;
                Notification nProgress=new Notification.Builder(context).setContentTitle(mAppTitle + "String_Node_Str").setContentText(indexItem.getTitle() + "String_Node_Str" + (nPercent / 10.0)+ "String_Node_Str").setSmallIcon(android.R.drawable.arrow_down_float).setProgress(100,(nPercent / 10),false).setWhen(startTime.getTime()).build();
                nManager.notify(nTag,nId,nProgress);
              }
            }
          }
          targetOutput.write(buf,0,i);
        }
        targetOutput.close();
        responseInput.close();
        Timber.d("String_Node_Str" + targetFile);
      }
 catch (      ConnectTimeoutException cte) {
        Timber.e("String_Node_Str" + actualFileName + "String_Node_Str");
        cte.printStackTrace();
      }
catch (      SocketTimeoutException ste) {
        Timber.e("String_Node_Str" + actualFileName + "String_Node_Str");
        ste.printStackTrace();
      }
catch (      IOException ioe) {
        Timber.e("String_Node_Str" + actualFileName + "String_Node_Str");
        ioe.printStackTrace();
      }
      StorymakerQueueManager.removeFromQueue(context,queueId,queueDao);
      nManager.cancel(nTag,nId);
      if (!handleFile(targetFile)) {
        Timber.e("String_Node_Str" + actualFileName);
      }
    }
 else {
      Timber.e("String_Node_Str" + actualFileName + "String_Node_Str"+ statusCode);
      StorymakerQueueManager.checkQueueFinished(context,targetFile.getName());
    }
  }
 catch (  IOException ioe) {
    Timber.e("String_Node_Str" + actualFileName + "String_Node_Str");
    ioe.printStackTrace();
    StorymakerQueueManager.checkQueueFinished(context,targetFile.getName());
  }
}

Fixed version (ground truth):
private void downloadWithTor(boolean useTor,Uri uri,String title,String desc,File targetFile){
  initNotificationManager();
  String nTag=indexItem.getExpansionId();
  int nId=0;
  if (fileName.contains(scal.io.liger.Constants.MAIN)) {
    nId=Integer.parseInt(indexItem.getExpansionFileVersion());
  }
 else   if (fileName.contains(scal.io.liger.Constants.PATCH)) {
    nId=Integer.parseInt(indexItem.getPatchFileVersion());
  }
  OkHttpClient httpClient=new OkHttpClient();
  if (useTor) {
    if (checkTor(context)) {
      Timber.d("String_Node_Str" + scal.io.liger.Constants.TOR_PROXY_HOST + "String_Node_Str"+ scal.io.liger.Constants.TOR_PROXY_PORT);
      SocketAddress torSocket=new InetSocketAddress(scal.io.liger.Constants.TOR_PROXY_HOST,scal.io.liger.Constants.TOR_PROXY_PORT);
      Proxy torProxy=new Proxy(Proxy.Type.HTTP,torSocket);
      httpClient.setProxy(torProxy);
    }
 else {
      Timber.e("String_Node_Str");
      if (context instanceof Activity) {
        Utils.toastOnUiThread((Activity)context,"String_Node_Str",true);
      }
      StorymakerQueueManager.checkQueueFinished(context,targetFile.getName());
      return;
    }
  }
  httpClient.setRetryOnConnectionFailure(false);
  httpClient.setConnectTimeout(3000,TimeUnit.MILLISECONDS);
  String actualFileName=targetFile.getName().substring(0,targetFile.getName().lastIndexOf("String_Node_Str"));
  Timber.d("String_Node_Str" + uri.toString());
  try {
    Request request=new Request.Builder().url(uri.toString()).addHeader("String_Node_Str","String_Node_Str").build();
    File partFile=new File(targetFile.getPath().replace("String_Node_Str","String_Node_Str"));
    if (partFile.exists()) {
      long partBytes=partFile.length();
      Timber.d("String_Node_Str" + partFile.getPath() + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ Long.toString(partBytes)+ "String_Node_Str");
      request=new Request.Builder().url(uri.toString()).addHeader("String_Node_Str","String_Node_Str").addHeader("String_Node_Str","String_Node_Str" + Long.toString(partBytes) + "String_Node_Str").build();
    }
 else {
      Timber.d("String_Node_Str" + partFile.getPath() + "String_Node_Str");
    }
    Response response=httpClient.newCall(request).execute();
    int statusCode=response.code();
    if ((statusCode == 200) || (statusCode == 206)) {
      Timber.d("String_Node_Str" + statusCode);
      Date startTime=new Date();
      long queueId=0 - startTime.getTime();
      StorymakerQueueManager.addToQueue(context,queueId,targetFile.getName(),queueDao);
      targetFile.getParentFile().mkdirs();
      Timber.d("String_Node_Str");
      BufferedInputStream responseInput=new BufferedInputStream(response.body().byteStream());
      try {
        FileOutputStream targetOutput=new FileOutputStream(targetFile);
        byte[] buf=new byte[1024];
        int i;
        int oldPercent=0;
        long thisTime;
        long lastTime=-1;
        int lastPercent=0;
        while ((i=responseInput.read(buf)) > 0) {
          int nPercent=StorymakerDownloadHelper.getDownloadPercent(context,fileName,installedDao);
          thisTime=System.currentTimeMillis();
          if (oldPercent == nPercent) {
          }
 else {
            if (nPercent % 10 == 0 && nPercent != lastPercent) {
              if (lastTime == -1 || (thisTime - lastTime) > 1000) {
                lastPercent=nPercent;
                oldPercent=nPercent;
                lastTime=thisTime;
                Notification nProgress=new Notification.Builder(context).setContentTitle(mAppTitle + "String_Node_Str").setContentText(indexItem.getTitle() + "String_Node_Str" + (nPercent / 10.0)+ "String_Node_Str").setSmallIcon(android.R.drawable.arrow_down_float).setProgress(100,(nPercent / 10),false).setWhen(startTime.getTime()).build();
                nManager.notify(nTag,nId,nProgress);
              }
            }
          }
          targetOutput.write(buf,0,i);
        }
        targetOutput.close();
        responseInput.close();
        Timber.d("String_Node_Str" + targetFile);
      }
 catch (      ConnectTimeoutException cte) {
        Timber.e("String_Node_Str" + actualFileName + "String_Node_Str");
        cte.printStackTrace();
      }
catch (      SocketTimeoutException ste) {
        Timber.e("String_Node_Str" + actualFileName + "String_Node_Str");
        ste.printStackTrace();
      }
catch (      IOException ioe) {
        Timber.e("String_Node_Str" + actualFileName + "String_Node_Str");
        ioe.printStackTrace();
      }
      StorymakerQueueManager.removeFromQueue(context,queueId,queueDao);
      nManager.cancel(nTag,nId);
      if (!handleFile(targetFile)) {
        Timber.e("String_Node_Str" + actualFileName);
      }
    }
 else {
      Timber.e("String_Node_Str" + actualFileName + "String_Node_Str"+ statusCode);
      StorymakerQueueManager.checkQueueFinished(context,targetFile.getName());
    }
  }
 catch (  IOException ioe) {
    Timber.e("String_Node_Str" + actualFileName + "String_Node_Str");
    ioe.printStackTrace();
    StorymakerQueueManager.checkQueueFinished(context,targetFile.getName());
  }
}