package c.b.a.u;

import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;

/* JADX INFO: Add missing generic type declarations: [T] */
/* JADX INFO: loaded from: classes.dex */
public class f<T> implements s<T> {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final x f1336a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final /* synthetic */ Class f1337b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final /* synthetic */ Type f1338c;

    public f(g gVar, Class cls, Type type) {
        x wVar;
        this.f1337b = cls;
        this.f1338c = type;
        try {
            Class<?> cls2 = Class.forName("sun.misc.Unsafe");
            Field declaredField = cls2.getDeclaredField("theUnsafe");
            declaredField.setAccessible(true);
            wVar = new t(cls2.getMethod("allocateInstance", Class.class), declaredField.get(null));
        } catch (Exception unused) {
            try {
                try {
                    Method declaredMethod = ObjectStreamClass.class.getDeclaredMethod("getConstructorId", Class.class);
                    declaredMethod.setAccessible(true);
                    int iIntValue = ((Integer) declaredMethod.invoke(null, Object.class)).intValue();
                    Method declaredMethod2 = ObjectStreamClass.class.getDeclaredMethod("newInstance", Class.class, Integer.TYPE);
                    declaredMethod2.setAccessible(true);
                    wVar = new u(declaredMethod2, iIntValue);
                } catch (Exception unused2) {
                    Method declaredMethod3 = ObjectInputStream.class.getDeclaredMethod("newInstance", Class.class, Class.class);
                    declaredMethod3.setAccessible(true);
                    wVar = new v(declaredMethod3);
                }
            } catch (Exception unused3) {
                wVar = new w();
            }
        }
        this.f1336a = wVar;
    }

    @Override // c.b.a.u.s
    public T a() {
        try {
            return (T) this.f1336a.b(this.f1337b);
        } catch (Exception e2) {
            StringBuilder sbD = c.a.a.a.a.d("Unable to invoke no-args constructor for ");
            sbD.append(this.f1338c);
            sbD.append(". Registering an InstanceCreator with Gson for this type may fix this problem.");
            throw new RuntimeException(sbD.toString(), e2);
        }
    }
}
