struberg commented on code in PR #1328:
URL: https://github.com/apache/commons-lang/pull/1328#discussion_r1884505527


##########
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 is a trade-off vs performance. it will only cache those classes which 
got hit in a reflection equals, toString, etc. Thus in practice it is a very 
limited set of classes I'd say. Can you think of a possible place where we can 
hold such a cache at least during a single invocation? Maybe inside the builder 
and handing the Map as another parameter to this method?



-- 
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]

Reply via email to