Here you can find the source of setField(Field field, Object target, Object value)
public static void setField(Field field, Object target, Object value)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Field; import java.lang.reflect.Modifier; public class Main { public static void setField(Field field, Object target, Object value) { try {/*from ww w . j av a 2s . c o m*/ makeAccessible(field); field.set(target, value); } catch (IllegalAccessException var4) { throw new IllegalStateException( "Unexpected reflection exception - " + var4.getClass().getName() + ": " + var4.getMessage()); } } public static void makeAccessible(Field field) { if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers()) || Modifier.isFinal(field.getModifiers())) && !field.isAccessible()) { field.setAccessible(true); } } }