8214795: Add safety check to dynalink inner class lookup
authorhannesw
Wed, 05 Dec 2018 19:17:22 +0100
changeset 52859 413c28945e0f
parent 52858 dad45affbdaa
child 52860 8dd8965df7f6
child 57061 ac44f38300b2
8214795: Add safety check to dynalink inner class lookup Reviewed-by: sundar, attila
src/jdk.dynalink/share/classes/jdk/dynalink/beans/AccessibleMembersLookup.java
--- a/src/jdk.dynalink/share/classes/jdk/dynalink/beans/AccessibleMembersLookup.java	Wed Dec 05 16:11:53 2018 +0100
+++ b/src/jdk.dynalink/share/classes/jdk/dynalink/beans/AccessibleMembersLookup.java	Wed Dec 05 19:17:22 2018 +0100
@@ -216,7 +216,10 @@
                 // were not yet loaded, they'll only get loaded in a non-resolved state; no static initializers for
                 // them will trigger just by doing this.
                 // Don't overwrite an inner class with an inherited inner class with the same name.
-                innerClasses.putIfAbsent(innerClass.getSimpleName(), innerClass);
+                Class<?> previousClass = innerClasses.get(innerClass.getSimpleName());
+                if (previousClass == null || previousClass.getDeclaringClass().isAssignableFrom(innerClass.getDeclaringClass())) {
+                    innerClasses.put(innerClass.getSimpleName(), innerClass);
+                }
             }
         } else {
             searchSuperTypes = true;