@Test void shouldForwardExceptionWhenSettingField() { Field field = getField("integer"); assertThrows(InjectorReflectionException.class, () -> ReflectionUtils.setField(field, new Object(), 3)); }
public static void setField(Field field, Object instance, Object value) { field.setAccessible(true); try { field.set(instance, value); } catch (IllegalAccessException | IllegalArgumentException e) { throw new InjectorReflectionException( "Could not set field '" + field.getName() + "' for " + instance, e); } }
ReflectionUtils { public static void setField(Field field, Object instance, Object value) { field.setAccessible(true); try { field.set(instance, value); } catch (IllegalAccessException | IllegalArgumentException e) { throw new InjectorReflectionException( "Could not set field '" + field.getName() + "' for " + instance, e); } } }
ReflectionUtils { public static void setField(Field field, Object instance, Object value) { field.setAccessible(true); try { field.set(instance, value); } catch (IllegalAccessException | IllegalArgumentException e) { throw new InjectorReflectionException( "Could not set field '" + field.getName() + "' for " + instance, e); } } private  ReflectionUtils(); }
ReflectionUtils { public static void setField(Field field, Object instance, Object value) { field.setAccessible(true); try { field.set(instance, value); } catch (IllegalAccessException | IllegalArgumentException e) { throw new InjectorReflectionException( "Could not set field '" + field.getName() + "' for " + instance, 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 void setField(Field field, Object instance, Object value) { field.setAccessible(true); try { field.set(instance, value); } catch (IllegalAccessException | IllegalArgumentException e) { throw new InjectorReflectionException( "Could not set field '" + field.getName() + "' for " + instance, 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);  }