<commit_before>package com.fsck.k9.helper;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.os.Build;
import android.content.Intent;
import android.util.Log;
import com.fsck.k9.K9;
import com.fsck.k9.mail.Address;

/**
 * Helper class to access the contacts stored on the device. This is needed
 * because the original contacts API introduced with SDK 1 was deprecated with
 * SDK 5 and will eventually be removed in newer SDK versions.
 * A class that uses the latest contacts API available on the device will be
 * loaded at runtime.
 *
 * @see ContactsSdk5
 * @see ContactsSdk5p
 */
public abstract class Contacts {
    /**
     * Instance of the SDK specific class that interfaces with the contacts
     * API.
     */
    private static Contacts sInstance = null;

    /**
     * Get SDK specific instance of the Contacts class.
     *
     * @param context A {@link Context} instance.
     * @return Appropriate {@link Contacts} instance for this device.
     */
    public static Contacts getInstance(Context context) {
        if (sInstance == null) {
            /*
             * Check the version of the SDK we are running on. Choose an
             * implementation class designed for that version of the SDK.
             */
            String className = null;
            if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ECLAIR_MR1) {
                /*
                 * The new API was introduced with SDK 5. But Android versions < 2.2
                 * need some additional code to be able to search for phonetic names.
                 */
                className = "com.fsck.k9.helper.ContactsSdk5p";
            } else {
                className = "com.fsck.k9.helper.ContactsSdk5";
            }

            /*
             * Find the required class by name and instantiate it.
             */
            try {
                Class <? extends Contacts > clazz =
                    Class.forName(className).asSubclass(Contacts.class);

                Constructor <? extends Contacts > constructor = clazz.getConstructor(Context.class);
                sInstance = constructor.newInstance(context);
            } catch (ClassNotFoundException e) {
                Log.e(K9.LOG_TAG, "Couldn't find class: " + className, e);
            } catch (InstantiationException e) {
                Log.e(K9.LOG_TAG, "Couldn't instantiate class: " + className, e);
            } catch (IllegalAccessException e) {
                Log.e(K9.LOG_TAG, "Couldn't access class: " + className, e);
            } catch (NoSuchMethodException e) {
                Log.e(K9.LOG_TAG, "Couldn't find constructor of class: " + className, e);
            } catch (IllegalArgumentException e) {
                Log.e(K9.LOG_TAG, "Wrong arguments for constructor of class: " + className, e);
            } catch (InvocationTargetException e) {
                Log.e(K9.LOG_TAG, "Couldn't invoke constructor of class: " + className, e);
            }
        }

        return sInstance;
    }


    protected Context mContext;
    protected ContentResolver mContentResolver;
    protected Boolean mHasContactPicker;
<commit_msg>Don't use reflection to load the API-specific Contacts implementation<commit_after>package com.fsck.k9.helper;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.os.Build;
import android.content.Intent;
import com.fsck.k9.mail.Address;

/**
 * Helper class to access the contacts stored on the device. This is needed
 * because the original contacts API introduced with SDK 1 was deprecated with
 * SDK 5 and will eventually be removed in newer SDK versions.
 * A class that uses the latest contacts API available on the device will be
 * loaded at runtime.
 *
 * @see ContactsSdk5
 * @see ContactsSdk5p
 */
public abstract class Contacts {
    /**
     * Instance of the SDK specific class that interfaces with the contacts
     * API.
     */
    private static Contacts sInstance = null;

    /**
     * Get SDK specific instance of the Contacts class.
     *
     * @param context A {@link Context} instance.
     * @return Appropriate {@link Contacts} instance for this device.
     */
    public static Contacts getInstance(Context context) {
        if (sInstance == null) {
            /*
             * Check the version of the SDK we are running on. Choose an
             * implementation class designed for that version of the SDK.
             */
            if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ECLAIR_MR1) {
                /*
                 * The new API was introduced with SDK 5. But Android versions < 2.2
                 * need some additional code to be able to search for phonetic names.
                 */
                sInstance = new ContactsSdk5p(context);
            } else {
                sInstance = new ContactsSdk5(context);
            }
        }

        return sInstance;
    }


    protected Context mContext;
    protected ContentResolver mContentResolver;
    protected Boolean mHasContactPicker;

{'fraction_non_alphanumeric': 0.07895745496358758, 'fraction_numerical': 0.006515906477577616, 'mean_word_length': 2.194002447980416, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4994972', 'n_tokens_mistral': 1402, 'n_tokens_neox': 1335, 'n_words': 476}