package uk;

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

/* loaded from: classes3.dex */
public abstract class l {

    /* loaded from: classes3.dex */
    class a extends l {

        /* renamed from: a, reason: collision with root package name */
        final /* synthetic */ Method f37308a;

        /* renamed from: b, reason: collision with root package name */
        final /* synthetic */ Object f37309b;

        a(Method method, Object obj) {
            this.f37308a = method;
            this.f37309b = obj;
        }

        @Override // uk.l
        public Object c(Class cls) {
            l.a(cls);
            return this.f37308a.invoke(this.f37309b, cls);
        }
    }

    /* loaded from: classes3.dex */
    class b extends l {

        /* renamed from: a, reason: collision with root package name */
        final /* synthetic */ Method f37310a;

        /* renamed from: b, reason: collision with root package name */
        final /* synthetic */ int f37311b;

        b(Method method, int i10) {
            this.f37310a = method;
            this.f37311b = i10;
        }

        @Override // uk.l
        public Object c(Class cls) {
            l.a(cls);
            return this.f37310a.invoke(null, cls, Integer.valueOf(this.f37311b));
        }
    }

    /* loaded from: classes3.dex */
    class c extends l {

        /* renamed from: a, reason: collision with root package name */
        final /* synthetic */ Method f37312a;

        c(Method method) {
            this.f37312a = method;
        }

        @Override // uk.l
        public Object c(Class cls) {
            l.a(cls);
            return this.f37312a.invoke(null, cls, Object.class);
        }
    }

    /* loaded from: classes3.dex */
    class d extends l {
        d() {
        }

        @Override // uk.l
        public Object c(Class cls) {
            throw new UnsupportedOperationException("Cannot allocate " + cls + ". Usage of JDK sun.misc.Unsafe is enabled, but it could not be used. Make sure your runtime is configured correctly.");
        }
    }

    static void a(Class cls) {
        int modifiers = cls.getModifiers();
        if (Modifier.isInterface(modifiers)) {
            throw new UnsupportedOperationException("Interface can't be instantiated! Interface name: " + cls.getName());
        }
        if (Modifier.isAbstract(modifiers)) {
            throw new UnsupportedOperationException("Abstract class can't be instantiated! Class name: " + cls.getName());
        }
    }

    public static l b() {
        try {
            Class<?> cls = Class.forName("sun.misc.Unsafe");
            Field declaredField = cls.getDeclaredField("theUnsafe");
            declaredField.setAccessible(true);
            return new a(cls.getMethod("allocateInstance", Class.class), declaredField.get(null));
        } catch (Exception unused) {
            try {
                try {
                    Method declaredMethod = ObjectStreamClass.class.getDeclaredMethod("getConstructorId", Class.class);
                    declaredMethod.setAccessible(true);
                    int intValue = ((Integer) declaredMethod.invoke(null, Object.class)).intValue();
                    Method declaredMethod2 = ObjectStreamClass.class.getDeclaredMethod("newInstance", Class.class, Integer.TYPE);
                    declaredMethod2.setAccessible(true);
                    return new b(declaredMethod2, intValue);
                } catch (Exception unused2) {
                    Method declaredMethod3 = ObjectInputStream.class.getDeclaredMethod("newInstance", Class.class, Class.class);
                    declaredMethod3.setAccessible(true);
                    return new c(declaredMethod3);
                }
            } catch (Exception unused3) {
                return new d();
            }
        }
    }

    public abstract Object c(Class cls);
}
