code: public static void setPrivateField(final Object obj, final String name, final Object value) {
          try {
              final Field field = obj.getClass().getDeclaredField(name);
              field.setAccessible(true);
              field.set(obj, value);
          } catch (final Exception ex) {
              throw new RuntimeException("Couldn't set field '" + name + "' in class '" + obj.getClass() + "'", ex);
          }
      }
docs: Sets a private field in an object by using reflection.
  
  @param obj
  Object with the attribute to set.
  @param name
  Name of the attribute to set.
  @param value
  Value to set for the attribute.