public static void setFieldValue(final Class<?> source, final Object target, final String fieldName, final Object value) throws NoSuchFieldException
    {
        try
        {
            AccessController.doPrivileged(new PrivilegedExceptionAction<Void>()
            {
                @Override
                public Void run() throws Exception
                {
                    Field field = source.getDeclaredField(fieldName);
                    if(!field.isAccessible())
                    {
                        field.setAccessible(true);
                    }
                    field.set(target, value);
                    return null;
                }
            });
        }
        // Unwrap
        catch (final PrivilegedActionException pae)
        {
            final Throwable t = pae.getCause();
            // Rethrow
            if (t instanceof NoSuchFieldException)
            {
                throw (NoSuchFieldException) t;
            }
            else
            {
                // No other checked Exception thrown by Class.getConstructor
                try
                {
                    throw (RuntimeException) t;
                }
                // Just in case we've really messed up
                catch (final ClassCastException cce)
                {
                    throw new RuntimeException("Obtained unchecked Exception; this code should never be reached", t);
                }
            }
        }
    }
public static void setFieldValue ( final Class < ? > source , final Object target , final String fieldName , final Object value ) throws NoSuchFieldException { try { AccessController . doPrivileged ( new PrivilegedExceptionAction < Void > ( ) { @ Override public Void run ( ) throws Exception { Field field = source . getDeclaredField ( fieldName ) ; if ( ! field . isAccessible ( ) ) { field . setAccessible ( true ) ; } field . set ( target , value ) ; return null ; } } ) ; } catch ( final PrivilegedActionException pae ) { final Throwable t = pae . getCause ( ) ; if ( t instanceof NoSuchFieldException ) { throw ( NoSuchFieldException ) t ; } else { try { throw ( RuntimeException ) t ; } catch ( final ClassCastException cce ) { throw new RuntimeException ( "Obtained unchecked Exception; this code should never be reached" , t ) ; } } } }
Set a single Field value

@param target The object to set it on
@param fieldName The field name
@param value The new value