Implement in inner class in domain class decorator to ensure access to private and protected fields

@param field
@param object
@throws IllegalAccessException
511029
protected void setField(Field field, Object object) throws IllegalAccessException {
		dataObject.setField(field, object);
	}
20
static Field lookupField(Class<?> javaClass, String fieldName) throws NoSuchFieldException {
        if (System.getSecurityManager() != null) {
            try {
                return AccessController.doPrivileged(new FieldLookupAction(javaClass, fieldName));
            } catch (PrivilegedActionException e) {
                if (e.getCause() instanceof NoSuchFieldException) {
                    throw (NoSuchFieldException) e.getCause();
                }
                throw new WeldException(e.getCause());
            }
        } else {
            return FieldLookupAction.lookupField(javaClass, fieldName);
        }
    }
365425
public static Field makeAccessible(Field field) {
        if (field == null) {
            throw new IllegalArgumentException("Method argument field must not be null.");
        }
        if (isInaccessible(field) && !field.isAccessible()) {
            field.setAccessible(true);
        }

        return field;
    }
152963
@SuppressWarnings({ "unchecked", "TryWithIdenticalCatches" })
  public static void writeField(
      @NonNull Object value, @NonNull Class<?> enclosingClass,
      @NonNull Object target, @NonNull String field) {
    try {
      Field f = enclosingClass.getDeclaredField(field);
      f.setAccessible(true);
      f.set(target, value);
    } catch (NoSuchFieldException e) {
      throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
      throw new RuntimeException(e);
    }
  }
954076
public static Object getValue(Field field, Object object) {
		String fieldName = field.getName();
		String setMethodName = "get" + firstLetterUpperCase(fieldName);
		Method method = null;
		try {
			method = object.getClass().getMethod(setMethodName);
		} catch (Exception e) {
		}
		
		if(method != null) {
			try {
				return method.invoke(object);
			} catch (Exception e) {
				LOGGER.error("method invoke", e);
			}
		}
		
		field.setAccessible(true);
		try {
			return field.get(object);
		} catch (Exception e) {
			LOGGER.error("method invoke", e);
			return null;
		}
	}
73794
public void setValue(Object obj, T value) throws IllegalAccessException, InvocationTargetException {
		if (field == null) {
			setMethod.invoke(obj, value);
		} else {
			field.set(obj, value);
		}
	}
1372744
private void writeObject(ObjectOutputStream out) throws IOException {
        PutField fields = out.putFields();
        fields.put(AUTH_METHOD, authMethod);
        fields.put(ACCESS_ID, accessId);
        fields.put(SECURITY_NAME, securityName);
        out.writeFields();
    }
184334
private int determineVisibilityForSharedFieldAccessor(Field field) {
    if (field.getOwner() == null) { // true field
      int visibility = AstUtil.getVisibility(field.getAst());
      if (visibility == Opcodes.ACC_PRIVATE) visibility = Opcodes.ACC_PROTECTED;
      return visibility;
    } else { // property
      return Opcodes.ACC_PUBLIC;
    }
  }
694913
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);
        }
    }
367825
private void checkOrMarkPrivateAccess(Expression source, FieldNode fn) {
        if (fn!=null && Modifier.isPrivate(fn.getModifiers()) &&
            (fn.getDeclaringClass() != typeCheckingContext.getEnclosingClassNode() || typeCheckingContext.getEnclosingClosure()!=null) &&
            fn.getDeclaringClass().getModule() == typeCheckingContext.getEnclosingClassNode().getModule()) {
            addPrivateFieldOrMethodAccess(source, fn.getDeclaringClass(), StaticTypesMarker.PV_FIELDS_ACCESS, fn);
        }
    }
474009
protected void setValueToField(Field field, Object bean, Object value) {
        try {
            field.setAccessible(true);
            field.set(bean, value);
        } catch (Exception e) {
            throw new PropertyLoaderException(
                    String.format("Can not set bean <%s> field <%s> value", bean, field), e
            );
        }
    }
553648
private static void setField(Class<?> expectedType, Object value, boolean saveOriginal) throws IllegalStateException {
        try {
            for (Field field : NamingManager.class.getDeclaredFields()) {
                if (expectedType.equals(field.getType())) {
                    field.setAccessible(true);
                    if (saveOriginal) {
                        if (expectedType.equals(InitialContextFactoryBuilder.class)) {
                            originalICFBuilder = (InitialContextFactoryBuilder) field.get(null);
                        } else {
                            originalOFBuilder = (ObjectFactoryBuilder) field.get(null);
                        }
                    }

                    field.set(null, value);
                }
            }
        } catch (Throwable t) {
            // Ignore
            LOGGER.debug("Error setting field.", t);
            throw new IllegalStateException(t);
        }
    }
1373042
protected void setField(Object component, Field field, Object proxy) {
        try {
            checkAccessabilityOfField(field);
            field.set(component, proxy);
        } catch (Exception e) {
            throw new RuntimeException("Bumm", e);
        }
    }
246417
private static void setField(Object object, Object value, Field foundField) {
        foundField.setAccessible(true);
        try {
            int fieldModifiersMask = foundField.getModifiers();
            removeFinalModifierIfPresent(foundField);
            foundField.set(object, value);
            restoreModifiersToFieldIfChanged(fieldModifiersMask, foundField);
        } catch (IllegalAccessException e) {
            throw new RuntimeException("Internal error: Failed to set field in method setInternalState.", e);
        }
    }
1360192
private void setField(Field field, Object targetObject, Object value) throws UnmarshalException{
		field.setAccessible(true);
		try {
			field.set(targetObject, value);
		} catch (IllegalArgumentException e) {
			throw new UnmarshalException(e);
		} catch (IllegalAccessException e) {
			throw new UnmarshalException(e);
		}
	}
452352
@Trivial
    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
        GetField fields = in.readFields();
        domain = (String) fields.get(DOMAIN, null);
        id = (String) fields.get(ID, null);
    }
59590
public static void setPrivateAttribute(HttpServletRequest req, String key, Object object) {
        HttpServletRequest sr = getWrappedServletRequestObject(req);
        if (sr instanceof IPrivateRequestAttributes) {
            ((IPrivateRequestAttributes) sr).setPrivateAttribute(key, object);
        } else {
            if (tc.isDebugEnabled()) {
                Tr.debug(tc, "getPrivateAttribute called for non-IPrivateRequestAttributes object", req);
            }
        }
    }