Fixed type resolution for uninitialized factory-method declaration

Issue: SPR-11112
(cherry picked from commit 5dcd287)
This commit is contained in:
Juergen Hoeller
2013-12-10 13:12:32 +01:00
parent 71650c0a44
commit 8e52e650f4
7 changed files with 151 additions and 44 deletions

View File

@@ -1155,6 +1155,39 @@ public abstract class ClassUtils {
return Proxy.getProxyClass(classLoader, interfaces);
}
/**
* Determine the common ancestor of the given classes, if any.
* @param clazz1 the class to introspect
* @param clazz2 the other class to introspect
* @return the common ancestor (i.e. common superclass, one interface
* extending the other), or {@code null} if none found. If any of the
* given classes is {@code null}, the other class will be returned.
* @since 3.2.6
*/
public static Class<?> determineCommonAncestor(Class<?> clazz1, Class<?> clazz2) {
if (clazz1 == null) {
return clazz2;
}
if (clazz2 == null) {
return clazz1;
}
if (clazz1.isAssignableFrom(clazz2)) {
return clazz1;
}
if (clazz2.isAssignableFrom(clazz1)) {
return clazz2;
}
Class<?> ancestor = clazz1;
do {
ancestor = ancestor.getSuperclass();
if (ancestor == null || Object.class.equals(ancestor)) {
return null;
}
}
while (!ancestor.isAssignableFrom(clazz2));
return ancestor;
}
/**
* Check whether the given class is visible in the given ClassLoader.
* @param clazz the class to check (typically an interface)