public class ConstructorReflection {
@SuppressWarnings("restriction")
public static Object newInstance(Constructor<?> method, Object... args) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, InstantiationException {
final MethodData data = ClassDataStore.instance().getMethodInformation(method.getDeclaringClass().getName());
final Class<?> info = ClassDataStore.instance().getRealClassFromProxyName(method.getDeclaringClass().getName());
try {
final Constructor<?> invoke = info.getConstructor(int.class, Object[].class, ConstructorArgument.class);
Object ar = args;
if (ar == null) {
ar = new Object[0];
}
if (!Modifier.isPublic(method.getModifiers()) && !method.isAccessible()) {
Class<?> caller = sun.reflect.Reflection.getCallerClass(2);
Reflection.ensureMemberAccess(caller, method.getDeclaringClass(), null, method.getModifiers());
}
return invoke.newInstance(data.getMethodNo(), ar, null);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
} catch (SecurityException e) {
throw new RuntimeException(e);
}