Package org.apache.commons.lang3.builder
Class AbstractReflection
java.lang.Object
org.apache.commons.lang3.builder.AbstractReflection
- Direct Known Subclasses:
CompareToBuilder,EqualsBuilder,HashCodeBuilder,ReflectionDiffBuilder,ToStringBuilder
Abstracts reflection access for reflection-based classes in this package.
See AbstractReflection.AbstractBuilder.setForceAccessible(boolean) for details.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilds an instance of a subclass ofAbstractReflection. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanWhether to callAccessibleObject#setAccessible(true)on inaccessible fields. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractReflection(AbstractReflection.AbstractBuilder<T> builder) Constructs a new instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanGets whether the system property"AbstractReflection.forceAccessible"is set to true.protected booleanTests whether fields should be made accessible withAccessibleObject.setAccessible(boolean).(package private) static boolean(package private) static voidstatic booleansetAccessible(boolean forceAccessible, AccessibleObject accessibleObject) SetsaccessibleObjectto be accessible ifforceAccessibleis true and the object is not already accessible.(package private) booleansetAccessible(Field field) Sets the field to be accessible ifforceAccessibleis true and the field is not already accessible.private static booleansetAccessibleTrue(AccessibleObject accessibleObject) Sets the accessible object as accessible by callingAccessibleObject#setAccessible(true).toRegisterPair(Object lhs, Object rhs) Converters value pair into a register pair.(package private) static voidunregister(Object lhs, Object rhs, Set<Pair<IDKey, IDKey>> registry, ThreadLocal<Set<Pair<IDKey, IDKey>>> registryTL)
-
Field Details
-
forceAccessible
private final boolean forceAccessibleWhether to callAccessibleObject#setAccessible(true)on inaccessible fields.
-
-
Constructor Details
-
AbstractReflection
AbstractReflection(AbstractReflection.AbstractBuilder<T> builder) Constructs a new instance.- Type Parameters:
T- The type to build.- Parameters:
builder- The builder.
-
-
Method Details
-
getForceAccessible
public static boolean getForceAccessible()Gets whether the system property"AbstractReflection.forceAccessible"is set to true.The parsing rules are defined by
Boolean.parseBoolean(String).If the property is not set, return true.
- Returns:
- whether the system property
"AbstractReflection.forceAccessible"is set to true with true as the default. - Since:
- 3.21.0
- See Also:
-
isRegistered
-
register
-
setAccessible
SetsaccessibleObjectto be accessible ifforceAccessibleis true and the object is not already accessible. CallsAccessibleObject#setAccessible(true).- Parameters:
forceAccessible- Whether to callAccessibleObject.setAccessible(boolean)if the object is not already accessible.accessibleObject- The accessible object to set; may benull.- Returns:
trueifaccessibleObjectis non-null and accessible after this call;falseotherwise (including whenaccessibleObjectisnull, or when it is inaccessible andforceAccessibleisfalse).- Throws:
SecurityException- Thrown ifforceAccessibleis true and the request is denied.- See Also:
-
setAccessibleTrue
Sets the accessible object as accessible by callingAccessibleObject#setAccessible(true).Callers must ensure
accessibleObjectis non-null before calling this method.- Parameters:
accessibleObject- The accessible object to set; must be non-null.- Returns:
trueifaccessibleObjectis accessible after this call;falseotherwise.- Throws:
SecurityException- Thrown if the request is denied.- See Also:
-
toRegisterPair
Converters value pair into a register pair.- Parameters:
lhs-thisobject.rhs- The other object.- Returns:
- The pair.
-
unregister
-
isForceAccessible
protected boolean isForceAccessible()Tests whether fields should be made accessible withAccessibleObject.setAccessible(boolean).- Returns:
- whether fields should be made accessible with
AccessibleObject.setAccessible(boolean).
-
setAccessible
Sets the field to be accessible ifforceAccessibleis true and the field is not already accessible. CallsAccessibleObject#setAccessible(true).- Parameters:
field- The field to set; may benull.- Returns:
trueiffieldis non-null and accessible after this call;falseotherwise.- Throws:
SecurityException- Thrown ifforceAccessibleflag is true and the request is denied.- See Also:
-