package kotlin.reflect.jvm.internal.impl.descriptors.runtime.structure;

import defpackage.cr4;
import defpackage.kp6;
import defpackage.pq6;
import defpackage.vx8;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/* JADX INFO: loaded from: classes3.dex */
@vx8
final class Java8ParameterNamesLoader {

    @kp6
    public static final Java8ParameterNamesLoader INSTANCE = new Java8ParameterNamesLoader();

    @pq6
    private static Cache cache;

    public static final class Cache {

        @pq6
        private final Method getName;

        @pq6
        private final Method getParameters;

        public Cache(@pq6 Method method, @pq6 Method method2) {
            this.getParameters = method;
            this.getName = method2;
        }

        @pq6
        public final Method getGetName() {
            return this.getName;
        }

        @pq6
        public final Method getGetParameters() {
            return this.getParameters;
        }
    }

    private Java8ParameterNamesLoader() {
    }

    @kp6
    public final Cache buildCache(@kp6 Member member) {
        cr4.g(member, "member");
        Class<?> cls = member.getClass();
        try {
            return new Cache(cls.getMethod("getParameters", null), ReflectClassUtilKt.getSafeClassLoader(cls).loadClass("java.lang.reflect.Parameter").getMethod("getName", null));
        } catch (NoSuchMethodException unused) {
            return new Cache(null, null);
        }
    }

    @pq6
    public final List<String> loadParameterNames(@kp6 Member member) {
        Method getName;
        cr4.g(member, "member");
        Cache cacheBuildCache = cache;
        if (cacheBuildCache == null) {
            synchronized (this) {
                cacheBuildCache = cache;
                if (cacheBuildCache == null) {
                    cacheBuildCache = INSTANCE.buildCache(member);
                    cache = cacheBuildCache;
                }
            }
        }
        Method getParameters = cacheBuildCache.getGetParameters();
        if (getParameters == null || (getName = cacheBuildCache.getGetName()) == null) {
            return null;
        }
        Object objInvoke = getParameters.invoke(member, null);
        cr4.e(objInvoke, "null cannot be cast to non-null type kotlin.Array<*>");
        Object[] objArr = (Object[]) objInvoke;
        ArrayList arrayList = new ArrayList(objArr.length);
        for (Object obj : objArr) {
            Object objInvoke2 = getName.invoke(obj, null);
            cr4.e(objInvoke2, "null cannot be cast to non-null type kotlin.String");
            arrayList.add((String) objInvoke2);
        }
        return arrayList;
    }
}
