[Demonstration 1]

[Buggy Method]
public static void installApkFile(Context context, File file) {
    //        Intent intent = new Intent(Intent.ACTION_VIEW);
    //        if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ) {
    //            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    //            Uri contentUri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", file);
    //            intent.setDataAndType(contentUri, "application/vnd.android.package-archive");
    //        } else {
    //            intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    //            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    //        }
    //        context.startActivity(intent);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        Uri contentUri = FileProvider.getUriForFile(context, "com.cretin.www.cretinautoupdatelibrary.fileprovider", file);
        intent.setDataAndType(contentUri, "application/vnd.android.package-archive");
    } else {
        intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }
    if (context.getPackageManager().queryIntentActivities(intent, 0).size() > 0) {
        context.startActivity(intent);
    }
}

[Buggy Hunk]
Uri contentUri = FileProvider.getUriForFile(context, "com.cretin.www.cretinautoupdatelibrary.fileprovider", file);

[Patch]
Uri contentUri = FileProvider.getUriForFile(context, context.getPackageName()+".fileprovider", file);

[Demonstration 2]

[Buggy Method]
@Override
public void process(HttpServletRequest req, HttpServletResponse resp) {
    JSONObject ret = new JSONObject();
    VerifiedToken token = verifyUserToken(req);
    if (token != null) {
        String q = getStringParam(req, "q");
        Result result;
        switch(q) {
            case "getallcriteria":
                result = getAllCriteria();
                break;
            case "getstudentcriteria":
                result = getAllCriteriaOfStudent(token);
                break;
            case "addcriteria":
                result = addCriteria(token, req);
                break;
            default:
                result = null;
                break;
        }
        if (result != null) {
            if (result.getErrorCode() == ErrorCode.SUCCESS) {
                ret.put(RetCode.data, result.getData());
            }
            ret.put(RetCode.success, result.getErrorCode().getValue());
        } else {
            ret.put(RetCode.success, ErrorCode.FAIL.getValue());
        }
        if (token.isNewToken()) {
            setAuthTokenToCookie(resp, token.getToken());
        }
    } else {
        ret.put(RetCode.unauth, true);
        ret.put(RetCode.success, ErrorCode.ACCESS_DENIED.getValue());
    }
    response(req, resp, ret);
}

[Buggy Hunk]
if (result.getErrorCode() == ErrorCode.SUCCESS) {

[Patch]
if (result.getErrorCode() == ErrorCode.SUCCESS && result.getData() != null) {

[Demonstration 3]

[Buggy Method]
@Override
protected Integer doInBackground(UploadFilePayload... uploadFilePayloads) {
    final int MAX_BUFFER_SZ = 1 * 1024;
    Integer response_code = 0;
    JSONObject json = uploadFilePayloads[0].mJSONObject;
    mCallback = uploadFilePayloads[0].mCallbackContext;
    String file_path = json.optString("filePath");
    String upload_url = json.optString("serverUrl");
    JSONObject headers = json.optJSONObject("headers");
    HttpURLConnection huc = null;
    try {
        // retrieve params from JS
        int bytes_read, bytes_available, buffer_size, total_bytes;
        byte[] buffer;
        huc = (HttpURLConnection) new URL(upload_url).openConnection();
        // get file sz
        File file = new File(file_path);
        FileInputStream fis = new FileInputStream(file);
        bytes_available = fis.available();
        final int FILE_SZ = bytes_available;
        // set custom headers
        Iterator<?> keys = headers.keys();
        while (keys.hasNext()) {
            String key = (String) keys.next();
            String val = headers.getString(key);
            huc.setRequestProperty(key, val);
        }
        // urlConnection.setRequestProperty("Connection", "Keep-Alive");
        huc.setRequestProperty("Content-Length", "" + FILE_SZ);
        huc.setRequestProperty("User-Agent", System.getProperty("http.agent"));
        // config request
        huc.setUseCaches(false);
        huc.setDoInput(true);
        huc.setDoOutput(true);
        huc.setRequestMethod("POST");
        // urlConnection.setInstanceFollowRedirects(false);
        huc.setChunkedStreamingMode(1024 * 1000);
        // urlConnection.setFixedLengthStreamingMode(bytesAvailable);
        // read input file chunks + publish progress
        OutputStream out = huc.getOutputStream();
        buffer_size = Math.min(bytes_available, MAX_BUFFER_SZ);
        buffer = new byte[buffer_size];
        bytes_read = fis.read(buffer, 0, buffer_size);
        total_bytes = bytes_read;
        while (bytes_read > 0) {
            out.write(buffer, 0, buffer_size);
            bytes_available = fis.available();
            buffer_size = Math.min(bytes_available, MAX_BUFFER_SZ);
            bytes_read = fis.read(buffer, 0, buffer_size);
            total_bytes += bytes_read;
            publishProgress(buffer_size, total_bytes, FILE_SZ);
        }
        out.flush();
        out.close();
        // get server response
        response_code = huc.getResponseCode();
        String response_message = huc.getResponseMessage();
        // back to JS
        if (response_code / 100 != 2) {
            // error
            JSONObject json_error = new JSONObject();
            json_error.put("code", response_code);
            json_error.put("source", file_path);
            json_error.put("target", upload_url);
            json_error.put("message", response_message);
            PluginResult pr = new PluginResult(PluginResult.Status.ERROR, json_error);
            mCallback.sendPluginResult(pr);
        } else {
            // ok
            InputStream is = huc.getInputStream();
            StringBuilder sb = new StringBuilder();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String read;
            while ((read = br.readLine()) != null) {
                sb.append(read);
            }
            br.close();
            PluginResult pr = new PluginResult(PluginResult.Status.OK, sb.toString());
            mCallback.sendPluginResult(pr);
        }
    } catch (Exception e) {
        e.printStackTrace();
        JSONObject json_error = new JSONObject();
        try {
            json_error.put("code", -1);
            json_error.put("source", file_path);
            json_error.put("target", upload_url);
            json_error.put("message", e.getLocalizedMessage());
        } catch (JSONException ex) {
        }
        PluginResult pr = new PluginResult(PluginResult.Status.ERROR, json_error);
        mCallback.sendPluginResult(pr);
    } finally {
        if (huc != null) {
            huc.disconnect();
        }
    }
    return response_code;
}

[Buggy Hunk]
while (bytes_read > 0) {

[Patch]
while (bytes_read > 0 && huc.getErrorStream() == null) {