package com.google.gson.internal.a;

import com.bytedance.covode.number.Covode;
import com.google.gson.k;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;

public final class c extends b {
    public static Class LIZIZ;
    public final Object LIZJ = LIZ();
    public final Field LIZLLL = LIZIZ();

    static {
        Covode.recordClassIndex(45399);
    }

    public static Field LIZIZ() {
        try {
            return AccessibleObject.class.getDeclaredField("override");
        } catch (NoSuchFieldException unused) {
            return null;
        }
    }

    public static Object LIZ() {
        try {
            Class<?> cls = Class.forName("sun.misc.Unsafe");
            LIZIZ = cls;
            Field declaredField = cls.getDeclaredField("theUnsafe");
            declaredField.setAccessible(true);
            return declaredField.get((Object) null);
        } catch (Exception unused) {
            return null;
        }
    }

    public final void LIZ(AccessibleObject accessibleObject) {
        if (!LIZIZ(accessibleObject)) {
            try {
                accessibleObject.setAccessible(true);
            } catch (SecurityException e) {
                throw new k("Gson couldn't modify fields for " + accessibleObject + "\nand sun.misc.Unsafe not found.\nEither write a custom type adapter, or make fields accessible, or include sun.misc.Unsafe.", e);
            }
        }
    }

    private boolean LIZIZ(AccessibleObject accessibleObject) {
        if (!(this.LIZJ == null || this.LIZLLL == null)) {
            try {
                long longValue = ((Long) LIZIZ.getMethod("objectFieldOffset", new Class[]{Field.class}).invoke(this.LIZJ, new Object[]{this.LIZLLL})).longValue();
                LIZIZ.getMethod("putBoolean", new Class[]{Object.class, Long.TYPE, Boolean.TYPE}).invoke(this.LIZJ, new Object[]{accessibleObject, Long.valueOf(longValue), true});
                return true;
            } catch (Exception unused) {
            }
        }
        return false;
    }
}
