changeset 790:c806c8c82264

8034962: Dynalink to handle superclasses more carefully Reviewed-by: ahgross, attila, jlaskey
author sundar
date Fri, 21 Feb 2014 10:31:40 +0530
parents fbfb7048a523
children 0eaa55c7abe5
files src/jdk/internal/dynalink/beans/AccessibleMembersLookup.java src/jdk/internal/dynalink/beans/FacetIntrospector.java
diffstat 2 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk/internal/dynalink/beans/AccessibleMembersLookup.java	Fri Feb 21 10:01:59 2014 +0530
+++ b/src/jdk/internal/dynalink/beans/AccessibleMembersLookup.java	Fri Feb 21 10:31:40 2014 +0530
@@ -211,7 +211,8 @@
         if(!CheckRestrictedPackage.isRestrictedClass(clazz)) {
             searchSuperTypes = false;
             for(Method method: clazz.getMethods()) {
-                if(instance != Modifier.isStatic(method.getModifiers())) {
+                final boolean isStatic = Modifier.isStatic(method.getModifiers());
+                if(instance != isStatic) {
                     final MethodSignature sig = new MethodSignature(method);
                     if(!methods.containsKey(sig)) {
                         final Class<?> declaringClass = method.getDeclaringClass();
@@ -228,7 +229,10 @@
                             //generate the said synthetic delegators.
                             searchSuperTypes = true;
                         } else {
-                            methods.put(sig, method);
+                            // don't allow inherited static
+                            if (!isStatic || clazz == declaringClass) {
+                                methods.put(sig, method);
+                            }
                         }
                     }
                 }
@@ -245,7 +249,8 @@
             searchSuperTypes = true;
         }
 
-        if(searchSuperTypes) {
+        // don't need to search super types for static methods
+        if(instance && searchSuperTypes) {
             // If we reach here, the class is either not public, or it is in a restricted package. Alternatively, it is
             // public, but some of its methods claim that their declaring class is non-public. We'll try superclasses
             // and implemented interfaces then looking for public ones.
--- a/src/jdk/internal/dynalink/beans/FacetIntrospector.java	Fri Feb 21 10:01:59 2014 +0530
+++ b/src/jdk/internal/dynalink/beans/FacetIntrospector.java	Fri Feb 21 10:31:40 2014 +0530
@@ -136,7 +136,13 @@
         final Field[] fields = clazz.getFields();
         final Collection<Field> cfields = new ArrayList<>(fields.length);
         for(Field field: fields) {
-            if(instance != Modifier.isStatic(field.getModifiers()) && isAccessible(field)) {
+            final boolean isStatic = Modifier.isStatic(field.getModifiers());
+            if(isStatic && clazz != field.getDeclaringClass()) {
+                // ignore inherited static fields
+                continue;
+            }
+
+            if(instance != isStatic && isAccessible(field)) {
                 cfields.add(field);
             }
         }