From 38533393ba9922cd2c98fb7fafcd4f9b108f978c Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 15 Nov 2021 14:21:18 -0500 Subject: [PATCH] Internal refactoring. --- .../commons/lang3/reflect/FieldUtils.java | 2 +- .../commons/lang3/reflect/MemberUtils.java | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java b/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java index f2900a2ac..205f4afd4 100644 --- a/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java +++ b/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java @@ -107,7 +107,7 @@ public class FieldUtils { final Field field = acls.getDeclaredField(fieldName); // getDeclaredField checks for non-public scopes as well // and it returns accurate results - if (!Modifier.isPublic(field.getModifiers())) { + if (!MemberUtils.isPublic(field)) { if (!forceAccess) { continue; } diff --git a/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java b/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java index 703df269d..7f72f589e 100644 --- a/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java +++ b/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java @@ -30,7 +30,7 @@ import org.apache.commons.lang3.ClassUtils; * * @since 2.5 */ -abstract class MemberUtils { +final class MemberUtils { // TODO extract an interface to implement compareParameterSets(...)? private static final int ACCESS_TEST = Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE; @@ -57,7 +57,7 @@ abstract class MemberUtils { return false; } final Member m = (Member) obj; - if (!obj.isAccessible() && Modifier.isPublic(m.getModifiers()) && isPackageAccess(m.getDeclaringClass().getModifiers())) { + if (!obj.isAccessible() && isPublic(m) && isPackageAccess(m.getDeclaringClass().getModifiers())) { try { obj.setAccessible(true); return true; @@ -77,9 +77,18 @@ abstract class MemberUtils { return (modifiers & ACCESS_TEST) == 0; } + /** + * Tests whether a {@link Member} is public. + * @param member Member to test + * @return {@code true} if {@code m} is public + */ + static boolean isPublic(final Member member) { + return member != null && Modifier.isPublic(member.getModifiers()); + } + /** * Tests whether a {@link Member} is static. - * @param member Member to check + * @param member Member to test * @return {@code true} if {@code m} is static */ static boolean isStatic(final Member member) { @@ -88,11 +97,11 @@ abstract class MemberUtils { /** * Tests whether a {@link Member} is accessible. - * @param member Member to check + * @param member Member to test * @return {@code true} if {@code m} is accessible */ static boolean isAccessible(final Member member) { - return member != null && Modifier.isPublic(member.getModifiers()) && !member.isSynthetic(); + return member != null && isPublic(member) && !member.isSynthetic(); } /**