in kyuubi-relocated-hive-metastore-client/src/main/java/org/apache/kyuubi/shaded/hive/metastore/utils/JavaUtils.java [60:82]
public static <T> T newInstance(Class<T> theClass, Class<?>[] parameterTypes, Object[] initArgs) {
// Perform some sanity checks on the arguments.
if (parameterTypes.length != initArgs.length) {
throw new IllegalArgumentException(
"Number of constructor parameter types doesn't match number of arguments");
}
for (int i = 0; i < parameterTypes.length; i++) {
// initargs are boxed to Object, so we need to wrapper primitive types here.
Class<?> clazz = ClassUtils.primitiveToWrapper(parameterTypes[i]);
if (initArgs[i] != null && !(clazz.isInstance(initArgs[i]))) {
throw new IllegalArgumentException(
"Object : " + initArgs[i] + " is not an instance of " + clazz);
}
}
try {
Constructor<T> meth = theClass.getDeclaredConstructor(parameterTypes);
meth.setAccessible(true);
return meth.newInstance(initArgs);
} catch (Exception e) {
throw new RuntimeException("Unable to instantiate " + theClass.getName(), e);
}
}