package l3;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import n3.AbstractC0916c;
import p0.AbstractC0928a;
import q3.C0957b;

/* JADX INFO: loaded from: classes.dex */
public final class q extends o {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final HashMap f8947e;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Constructor f8948b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Object[] f8949c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final HashMap f8950d;

    static {
        HashMap map = new HashMap();
        map.put(Byte.TYPE, (byte) 0);
        map.put(Short.TYPE, (short) 0);
        map.put(Integer.TYPE, 0);
        map.put(Long.TYPE, 0L);
        map.put(Float.TYPE, Float.valueOf(0.0f));
        map.put(Double.TYPE, Double.valueOf(0.0d));
        map.put(Character.TYPE, (char) 0);
        map.put(Boolean.TYPE, Boolean.FALSE);
        f8947e = map;
    }

    public q(Class cls, LinkedHashMap linkedHashMap) {
        super(linkedHashMap);
        this.f8950d = new HashMap();
        b5.a aVar = AbstractC0916c.f9360a;
        Constructor constructorO = aVar.o(cls);
        this.f8948b = constructorO;
        AbstractC0916c.e(constructorO);
        String[] strArrT = aVar.t(cls);
        for (int i = 0; i < strArrT.length; i++) {
            this.f8950d.put(strArrT[i], Integer.valueOf(i));
        }
        Class<?>[] parameterTypes = this.f8948b.getParameterTypes();
        this.f8949c = new Object[parameterTypes.length];
        for (int i5 = 0; i5 < parameterTypes.length; i5++) {
            this.f8949c[i5] = f8947e.get(parameterTypes[i5]);
        }
    }

    @Override // l3.o
    public final Object c() {
        return (Object[]) this.f8949c.clone();
    }

    @Override // l3.o
    public final Object d(Object obj) {
        Object[] objArr = (Object[]) obj;
        Constructor constructor = this.f8948b;
        try {
            return constructor.newInstance(objArr);
        } catch (IllegalAccessException e2) {
            b5.a aVar = AbstractC0916c.f9360a;
            throw new RuntimeException("Unexpected IllegalAccessException occurred (Gson 2.10.1). Certain ReflectionAccessFilter features require Java >= 9 to work correctly. If you are not using ReflectionAccessFilter, report this to the Gson maintainers.", e2);
        } catch (IllegalArgumentException e6) {
            e = e6;
            throw new RuntimeException("Failed to invoke constructor '" + AbstractC0916c.b(constructor) + "' with args " + Arrays.toString(objArr), e);
        } catch (InstantiationException e7) {
            e = e7;
            throw new RuntimeException("Failed to invoke constructor '" + AbstractC0916c.b(constructor) + "' with args " + Arrays.toString(objArr), e);
        } catch (InvocationTargetException e8) {
            throw new RuntimeException("Failed to invoke constructor '" + AbstractC0916c.b(constructor) + "' with args " + Arrays.toString(objArr), e8.getCause());
        }
    }

    @Override // l3.o
    public final void e(Object obj, C0957b c0957b, n nVar) {
        Object[] objArr = (Object[]) obj;
        HashMap map = this.f8950d;
        String str = nVar.f8936c;
        Integer num = (Integer) map.get(str);
        if (num == null) {
            throw new IllegalStateException("Could not find the index in the constructor '" + AbstractC0916c.b(this.f8948b) + "' for field with name '" + str + "', unable to determine which argument in the constructor the field corresponds to. This is unexpected behavior, as we expect the RecordComponents to have the same names as the fields in the Java class, and that the order of the RecordComponents is the same as the order of the canonical constructor parameters.");
        }
        int iIntValue = num.intValue();
        Object objA = nVar.f8941h.a(c0957b);
        if (objA != null || !nVar.f8943k) {
            objArr[iIntValue] = objA;
        } else {
            StringBuilder sbN = AbstractC0928a.n("null is not allowed as value for record component '", str, "' of primitive type; at path ");
            sbN.append(c0957b.n());
            throw new A2.u(sbN.toString());
        }
    }
}
