108 lines
3.5 KiB
Java
108 lines
3.5 KiB
Java
|
package okhttp3.repackaged.internal;
|
||
|
|
||
|
import java.lang.reflect.InvocationTargetException;
|
||
|
import java.lang.reflect.Method;
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
class b<T> {
|
||
|
private final Class<?> ajj;
|
||
|
private final String ajk;
|
||
|
private final Class[] ajl;
|
||
|
|
||
|
public b(Class<?> cls, String str, Class... clsArr) {
|
||
|
this.ajj = cls;
|
||
|
this.ajk = str;
|
||
|
this.ajl = clsArr;
|
||
|
}
|
||
|
|
||
|
public boolean isSupported(T t) {
|
||
|
return b(t.getClass()) != null;
|
||
|
}
|
||
|
|
||
|
public Object invokeOptional(T t, Object... objArr) throws InvocationTargetException {
|
||
|
Method b = b(t.getClass());
|
||
|
if (b == null) {
|
||
|
return null;
|
||
|
}
|
||
|
try {
|
||
|
return b.invoke(t, objArr);
|
||
|
} catch (IllegalAccessException unused) {
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public Object invokeOptionalWithoutCheckedException(T t, Object... objArr) {
|
||
|
try {
|
||
|
return invokeOptional(t, objArr);
|
||
|
} catch (InvocationTargetException e) {
|
||
|
Throwable targetException = e.getTargetException();
|
||
|
if (targetException instanceof RuntimeException) {
|
||
|
throw ((RuntimeException) targetException);
|
||
|
}
|
||
|
AssertionError assertionError = new AssertionError("Unexpected exception");
|
||
|
assertionError.initCause(targetException);
|
||
|
throw assertionError;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public Object invoke(T t, Object... objArr) throws InvocationTargetException {
|
||
|
Method b = b(t.getClass());
|
||
|
if (b == null) {
|
||
|
StringBuilder sb = new StringBuilder("Method ");
|
||
|
sb.append(this.ajk);
|
||
|
sb.append(" not supported for object ");
|
||
|
sb.append(t);
|
||
|
throw new AssertionError(sb.toString());
|
||
|
}
|
||
|
try {
|
||
|
return b.invoke(t, objArr);
|
||
|
} catch (IllegalAccessException e) {
|
||
|
AssertionError assertionError = new AssertionError("Unexpectedly could not call: ".concat(String.valueOf(b)));
|
||
|
assertionError.initCause(e);
|
||
|
throw assertionError;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public Object invokeWithoutCheckedException(T t, Object... objArr) {
|
||
|
try {
|
||
|
return invoke(t, objArr);
|
||
|
} catch (InvocationTargetException e) {
|
||
|
Throwable targetException = e.getTargetException();
|
||
|
if (targetException instanceof RuntimeException) {
|
||
|
throw ((RuntimeException) targetException);
|
||
|
}
|
||
|
AssertionError assertionError = new AssertionError("Unexpected exception");
|
||
|
assertionError.initCause(targetException);
|
||
|
throw assertionError;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private Method b(Class<?> cls) {
|
||
|
Class<?> cls2;
|
||
|
String str = this.ajk;
|
||
|
if (str == null) {
|
||
|
return null;
|
||
|
}
|
||
|
Method publicMethod = getPublicMethod(cls, str, this.ajl);
|
||
|
if (publicMethod == null || (cls2 = this.ajj) == null || cls2.isAssignableFrom(publicMethod.getReturnType())) {
|
||
|
return publicMethod;
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
private static Method getPublicMethod(Class<?> cls, String str, Class[] clsArr) {
|
||
|
try {
|
||
|
Method method = cls.getMethod(str, clsArr);
|
||
|
try {
|
||
|
if ((method.getModifiers() & 1) == 0) {
|
||
|
return null;
|
||
|
}
|
||
|
} catch (NoSuchMethodException unused) {
|
||
|
}
|
||
|
return method;
|
||
|
} catch (NoSuchMethodException unused2) {
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
}
|