@Test void shouldForwardExceptionFromConstructor() throws NoSuchMethodException { Constructor<ReflectionsTestClass> constr = ReflectionsTestClass.class .getDeclaredConstructor(boolean.class); assertThrows(InjectorException.class, () -> ReflectionUtils.newInstance(constr, true)); }
public static <T> T newInstance(Constructor<T> constructor, Object... parameters) { constructor.setAccessible(true); try { return constructor.newInstance(parameters); } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) { throw new InjectorReflectionException("Could not invoke constructor of class '" + constructor.getDeclaringClass() + "'", e); } }
ReflectionUtils { public static <T> T newInstance(Constructor<T> constructor, Object... parameters) { constructor.setAccessible(true); try { return constructor.newInstance(parameters); } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) { throw new InjectorReflectionException("Could not invoke constructor of class '" + constructor.getDeclaringClass() + "'", e); } } }
ReflectionUtils { public static <T> T newInstance(Constructor<T> constructor, Object... parameters) { constructor.setAccessible(true); try { return constructor.newInstance(parameters); } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) { throw new InjectorReflectionException("Could not invoke constructor of class '" + constructor.getDeclaringClass() + "'", e); } } private  ReflectionUtils(); }
ReflectionUtils { public static <T> T newInstance(Constructor<T> constructor, Object... parameters) { constructor.setAccessible(true); try { return constructor.newInstance(parameters); } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) { throw new InjectorReflectionException("Could not invoke constructor of class '" + constructor.getDeclaringClass() + "'", e); } } private  ReflectionUtils(); static Object getFieldValue(Field field, Object instance); static void setField(Field field, Object instance, Object value); static Object invokeMethod(Method method, Object instance, Object... parameters); static T newInstance(Constructor<T> constructor, Object... parameters); @Nullable static Class<?> getGenericType(@Nullable Type genericType); @Nullable static Class<?> getCollectionType(Class<?> mainType, @Nullable Type genericType); static Object toSuitableCollectionType(Class<?> rawType, Set<T> result); static Method[] safeGetDeclaredMethods(Class<?> clazz); static Field[] safeGetDeclaredFields(Class<?> clazz); }
ReflectionUtils { public static <T> T newInstance(Constructor<T> constructor, Object... parameters) { constructor.setAccessible(true); try { return constructor.newInstance(parameters); } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) { throw new InjectorReflectionException("Could not invoke constructor of class '" + constructor.getDeclaringClass() + "'", e); } } private  ReflectionUtils(); static Object getFieldValue(Field field, Object instance); static void setField(Field field, Object instance, Object value); static Object invokeMethod(Method method, Object instance, Object... parameters); static T newInstance(Constructor<T> constructor, Object... parameters); @Nullable static Class<?> getGenericType(@Nullable Type genericType); @Nullable static Class<?> getCollectionType(Class<?> mainType, @Nullable Type genericType); static Object toSuitableCollectionType(Class<?> rawType, Set<T> result); static Method[] safeGetDeclaredMethods(Class<?> clazz); static Field[] safeGetDeclaredFields(Class<?> clazz);  }