package c.l;

import android.app.Application;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;

/* JADX INFO: compiled from: SavedStateViewModelFactory.kt */
/* JADX INFO: loaded from: classes.dex */
@g.i
public final class d0 {
    public static final List<Class<?>> a = g.c0.g.u(Application.class, y.class);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final List<Class<?>> f1767b = f.a.y.a.w0(y.class);

    public static final <T> Constructor<T> a(Class<T> cls, List<? extends Class<?>> list) {
        g.h0.c.l.f(cls, "modelClass");
        g.h0.c.l.f(list, "signature");
        Object[] constructors = cls.getConstructors();
        g.h0.c.l.e(constructors, "modelClass.constructors");
        for (Object obj : constructors) {
            Constructor<T> constructor = (Constructor<T>) obj;
            Class<?>[] parameterTypes = constructor.getParameterTypes();
            g.h0.c.l.e(parameterTypes, "constructor.parameterTypes");
            List listK1 = f.a.y.a.k1(parameterTypes);
            if (g.h0.c.l.a(list, listK1)) {
                return constructor;
            }
            if (list.size() == listK1.size() && listK1.containsAll(list)) {
                StringBuilder sbB = d.b.a.a.a.B("Class ");
                sbB.append(cls.getSimpleName());
                sbB.append(" must have parameters in the proper order: ");
                sbB.append(list);
                throw new UnsupportedOperationException(sbB.toString());
            }
        }
        return null;
    }

    public static final <T extends e0> T b(Class<T> cls, Constructor<T> constructor, Object... objArr) {
        g.h0.c.l.f(cls, "modelClass");
        g.h0.c.l.f(constructor, "constructor");
        g.h0.c.l.f(objArr, "params");
        try {
            return constructor.newInstance(Arrays.copyOf(objArr, objArr.length));
        } catch (IllegalAccessException e2) {
            throw new RuntimeException("Failed to access " + cls, e2);
        } catch (InstantiationException e3) {
            throw new RuntimeException("A " + cls + " cannot be instantiated.", e3);
        } catch (InvocationTargetException e4) {
            throw new RuntimeException("An exception happened in constructor of " + cls, e4.getCause());
        }
    }
}
