private static <T> Class<?> createReplicaType(Class<T> type, boolean isStatic, ConstructorArgs constructorArgs) { ClassReplicaCreator classReplicaCreator = new ClassReplicaCreator(); Class<?> replicaType = null; if (isStatic || constructorArgs == null) { replicaType = classReplicaCreator.createClassReplica(type); } else { try { replicaType = classReplicaCreator.createInstanceReplica(constructorArgs.getConstructor().newInstance(constructorArgs.getInitArgs())); } catch (RuntimeException e) { throw e; } catch (InvocationTargetException e) { Throwable targetException = ((InvocationTargetException) e).getTargetException(); if (targetException instanceof RuntimeException) { throw (RuntimeException) targetException; } throw new RuntimeException(e); } catch (Exception e) { throw new RuntimeException(e); } } return replicaType; }