ReflectTools implements Serializable { public static <T> T createProxyInstance(Class<T> proxyClass, Class<?> originalClass) { checkClassAccessibility(originalClass); try { Optional<Constructor<?>> constructor = Stream .of(proxyClass.getConstructors()) .filter(ctor -> ctor.getParameterCount() == 0).findFirst(); if (constructor.isPresent()) { return proxyClass.cast(constructor.get().newInstance()); } constructor = Stream.of(proxyClass.getConstructors()) .filter(ctor -> ctor.getParameterCount() == 1) .filter(ctor -> ctor.isVarArgs()).findFirst(); if (constructor.isPresent()) { Class<?> paramType = constructor.get().getParameterTypes()[0]; return proxyClass.cast(constructor.get().newInstance( Array.newInstance(paramType.getComponentType(), 0))); } } catch (InstantiationException e) { if (originalClass.isMemberClass() && !Modifier.isStatic(originalClass.getModifiers())) { throw new IllegalArgumentException(String.format( CREATE_INSTANCE_FAILED_FOR_NON_STATIC_MEMBER_CLASS, originalClass.getName()), e); } else { throw new IllegalArgumentException(String.format( CREATE_INSTANCE_FAILED, originalClass.getName()), e); } } catch (IllegalAccessException e) { throw new IllegalArgumentException( String.format(CREATE_INSTANCE_FAILED_ACCESS_EXCEPTION, originalClass.getName()), e); } catch (IllegalArgumentException e) { throw new IllegalArgumentException(String.format( CREATE_INSTANCE_FAILED, originalClass.getName()), e); } catch (InvocationTargetException e) { throw new IllegalArgumentException(String.format( CREATE_INSTANCE_FAILED_CONSTRUCTOR_THREW_EXCEPTION, originalClass.getName()), e); } throw new IllegalArgumentException(String.format( CREATE_INSTANCE_FAILED_NO_PUBLIC_NOARG_CONSTRUCTOR, originalClass.getName())); }  static Method findMethod(Class<?> cls, String methodName,
            Class<?>... parameterTypes); static Object getJavaFieldValue(Object object,
            java.lang.reflect.Field field); static Object getJavaFieldValue(Object object,
            java.lang.reflect.Field field, Class<?> propertyType); static void setJavaFieldValue(Object object,
            java.lang.reflect.Field field, Object value); static Class<?> convertPrimitiveType(Class<?> type); static Serializable getPrimitiveDefaultValue(
            Class<?> primitiveType); static boolean isSetter(Method method); static boolean isSetterName(String methodName); static boolean isGetterName(String methodName, boolean isBoolean); static boolean isGetter(Method method); static Stream<Method> getGetterMethods(Class<?> type); static Stream<Method> getSetterMethods(Class<?> type); static boolean isNotObjectMethod(Method method); static String getPropertyName(Method method); static Type getPropertyType(Method method); static T createInstance(Class<T> cls); static T createProxyInstance(Class<T> proxyClass,
            Class<?> originalClass); static void checkClassAccessibility(Class<?> clazz); static Type createParameterizedType(Class<?> rawType, Type subType); static Class<?> getGenericInterfaceType(Class<?> clazz,
            Class<?> interfaceType); static Optional<Method> getGetter(Class<? extends Object> beanClass,
            String propertyName); static boolean isCheckedException(Class<?> exceptionClass); static Method getFunctionalMethod(Class<?> functionalClass); static List<Integer> getConstantIntValues(Class<?> clazz); static Class<?> findCommonBaseType(Class<?> a, Class<?> b); static Optional<ClassLoader> findClosestCommonClassLoaderAncestor(
            ClassLoader classLoaderA, ClassLoader classLoaderB); static boolean hasAnnotation(AnnotatedElement element,
            String annotationFqn); static Object getAnnotationMethodValue(Annotation annotation,
            String methodName); static Optional<Annotation> getAnnotation(AnnotatedElement element,
            String annotationFqn);  }
@Test public void createProxyForNonStaticInnerClass() { Class<NonStaticInnerClass> originalClass = NonStaticInnerClass.class; Class<?> proxyClass = createProxyClass(originalClass); assertError( ReflectTools.CREATE_INSTANCE_FAILED_NO_PUBLIC_NOARG_CONSTRUCTOR, proxyClass); try { ReflectTools.createProxyInstance(proxyClass, originalClass); Assert.fail("Creation should cause an exception"); } catch (IllegalArgumentException re) { Assert.assertEquals(String.format( ReflectTools.CREATE_INSTANCE_FAILED_FOR_NON_STATIC_MEMBER_CLASS, originalClass.getName()), re.getMessage()); } }