<commit_before>package com.zulip.android.networking;

import android.os.AsyncTask;
import android.util.Base64;
import android.util.Log;

import com.zulip.android.R;
import com.zulip.android.ZulipApp;
import com.zulip.android.util.ZLog;

import org.apache.commons.lang.StringUtils;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Simplified HTTP request API
 * Uses the {@link OkHttpClient} for requests.
 */
public class HTTPRequest {
    private ZulipApp app;
    volatile boolean aborting = false;
    private HashMap<String, String> properties;
    private OkHttpClient okHttpClient;
    private Response response = null;
    private String method, path;

    public void setMethodAndUrl(String method, String URL) {
        this.method = method;
        this.path = URL;
    }

    public HTTPRequest(ZulipApp app) {
        properties = new HashMap<>();
        this.app = app;
        okHttpClient = new OkHttpClient.Builder().readTimeout(60, TimeUnit.SECONDS).build();
    }


    public void setProperty(String key, String value) {
        properties.put((key == null) ? "" : key, (value == null) ? "" : value);
    }

    void clearProperties() {
        properties.clear();
    }

    void abort() {
        aborting = true;
        if (response != null) {
            (new AsyncTask<Void, Void, Void>() {
                @Override
                protected Void doInBackground(Void... voids) {
                    response.body().close();
                    return null;
                }
            }).execute();
        }
    }

    public Response execute() throws IOException {<commit_msg>Race condition prevention and attempting to catch thread violations for aborting requests.<commit_after>package com.zulip.android.networking;

import android.os.AsyncTask;
import android.util.Base64;
import android.util.Log;

import com.zulip.android.R;
import com.zulip.android.ZulipApp;
import com.zulip.android.util.ZLog;

import org.apache.commons.lang.StringUtils;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Simplified HTTP request API
 * Uses the {@link OkHttpClient} for requests.
 */
public class HTTPRequest {
    private ZulipApp app;
    volatile boolean aborting = false;
    private HashMap<String, String> properties;
    private OkHttpClient okHttpClient;
    private Response response = null;
    private String method, path;
    private Object synchronization = new Object();

    public void setMethodAndUrl(String method, String URL) {
        this.method = method;
        this.path = URL;
    }

    public HTTPRequest(ZulipApp app) {
        properties = new HashMap<>();
        this.app = app;
        okHttpClient = new OkHttpClient.Builder().readTimeout(60, TimeUnit.SECONDS).build();
    }


    public void setProperty(String key, String value) {
        properties.put((key == null) ? "" : key, (value == null) ? "" : value);
    }

    void clearProperties() {
        properties.clear();
    }

    void abort() {
        aborting = true;
        synchronized (synchronization) {
            if (response != null) {
                final Response finalResponse = response;
                response = null;
                (new AsyncTask<Void, Void, Void>() {
                    @Override
                    protected Void doInBackground(Void... voids) {
                        try {
                            finalResponse.body().close();
                        } catch (IllegalStateException e) {
                            //fail silently
                        }
                        return null;
                    }
                }).execute();
            }
        }
    }

    public Response execute() throws IOException {
{'fraction_non_alphanumeric': 0.10095465393794749, 'fraction_numerical': 0.0038186157517899762, 'mean_word_length': 2.3716814159292037, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3871322', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1140, 'n_words': 296}