garydgregory commented on code in PR #1328:
URL: https://github.com/apache/commons-lang/pull/1328#discussion_r1875063686
##########
src/main/java/org/apache/commons/lang3/builder/Reflection.java:
##########
@@ -41,4 +90,44 @@ static Object getUnchecked(final Field field, final Object
obj) {
}
}
+ /**
+ * Check whether the class internas of the given object can be accessed.
This might return false in Java9
+ * and thus lead to a difference in behaviour if modularity is activated
or not.
+ * But it's the best we can do.
+ *
+ * @return {@code true} if the given class internas not accessible
+ */
+ static boolean isNonIntrospectibleClass(Object o) {
+ return o != null && isNonIntrospectibleClass(o.getClass());
+ }
+
+ /**
+ * Check whether the given class internas can be accessed. This might
return false in Java9
+ * and thus lead to a difference in behaviour if modularity is activated
or not.
+ * But it's the best we can do.
+ *
+ * @return {@code true} if the given class internas not accessible
+ */
+ static boolean isNonIntrospectibleClass(Class<?> clazz) {
+ if (KNOWN_NON_INTROSPECTIBLE_CLASSES.contains(clazz)) {
+ return true;
+ }
+ Boolean isAccessible = nonIntrospectibleClasses.get(clazz);
+ if (isAccessible != null) {
+ return isAccessible;
+ }
+ try {
+ final Field[] declaredFields = clazz.getDeclaredFields();
+ for (Field f : declaredFields) {
+ f.setAccessible(true);
+ }
+
+ nonIntrospectibleClasses.put(clazz, false);
Review Comment:
This looks problematic since the map will grow uncontrollably, possibly
until every class on your classpath gets referenced, there's no way to know
really.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]