<commit_before>package com.takisoft.fix.support.v7.preference;

import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.v4.view.ViewCompat;
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceViewHolder;
import android.support.v7.preference.PreferenceViewHolderProxy;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.lang.reflect.Field;
import java.util.List;

class PreferenceGroupAdapter extends android.support.v7.preference.PreferenceGroupAdapter {

    protected List mPreferenceLayouts;

    protected Field fieldResId;
    protected Field fieldWidgetResId;

    public PreferenceGroupAdapter(PreferenceGroup preferenceGroup) {
        super(preferenceGroup);

        try {
            Field preferenceLayoutsField = android.support.v7.preference.PreferenceGroupAdapter.class.getDeclaredField("mPreferenceLayouts");
            preferenceLayoutsField.setAccessible(true);
            mPreferenceLayouts = (List) preferenceLayoutsField.get(this);

            Class<?>[] classes = android.support.v7.preference.PreferenceGroupAdapter.class.getDeclaredClasses();
            for (Class<?> aClass : classes) {
                if ("PreferenceLayout".equals(aClass.getSimpleName())) {
                    fieldResId = aClass.getDeclaredField("resId");
                    fieldWidgetResId = aClass.getDeclaredField("widgetResId");

                    fieldResId.setAccessible(true);
                    fieldWidgetResId.setAccessible(true);

                    break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @NonNull
    private int[] getReflectedIds(Object pl) {
        int[] ids = new int[2];

        try {
            ids[0] = (int) fieldResId.get(pl);
            ids[1] = (int) fieldWidgetResId.get(pl);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        return ids;
    }
<commit_msg>Possible bugfix of a NullPointerException happening on some devices in PreferenceGroupAdapter's getReflectedIds(...)<commit_after>package com.takisoft.fix.support.v7.preference;

import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.v4.view.ViewCompat;
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceViewHolder;
import android.support.v7.preference.PreferenceViewHolderProxy;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.lang.reflect.Field;
import java.util.List;

class PreferenceGroupAdapter extends android.support.v7.preference.PreferenceGroupAdapter {

    protected List mPreferenceLayouts;

    protected Field fieldResId;
    protected Field fieldWidgetResId;

    public PreferenceGroupAdapter(PreferenceGroup preferenceGroup) {
        super(preferenceGroup);

        try {
            Field preferenceLayoutsField = android.support.v7.preference.PreferenceGroupAdapter.class.getDeclaredField("mPreferenceLayouts");
            preferenceLayoutsField.setAccessible(true);
            mPreferenceLayouts = (List) preferenceLayoutsField.get(this);

            getReflectionFields();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void getReflectionFields() {
        try {
            Class<?>[] classes = android.support.v7.preference.PreferenceGroupAdapter.class.getDeclaredClasses();
            for (Class<?> aClass : classes) {
                if ("PreferenceLayout".equals(aClass.getSimpleName())) {
                    fieldResId = aClass.getDeclaredField("resId");
                    fieldWidgetResId = aClass.getDeclaredField("widgetResId");

                    fieldResId.setAccessible(true);
                    fieldWidgetResId.setAccessible(true);

                    break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @NonNull
    private int[] getReflectedIds(Object pl) {
        int[] ids = new int[2];

        if (fieldResId == null || fieldWidgetResId == null) {
            getReflectionFields(); // try to resolve them again if it didn't happen so far
        }

        try {
            ids[0] = (int) fieldResId.get(pl);
            ids[1] = (int) fieldWidgetResId.get(pl);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        return ids;
    }

{'fraction_non_alphanumeric': 0.0962962962962963, 'fraction_numerical': 0.004656084656084656, 'mean_word_length': 2.7389240506329116, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4828651', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1264, 'n_words': 227}