commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1203429 - /commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java
Date Thu, 17 Nov 2011 23:59:37 GMT
Author: mbenson
Date: Thu Nov 17 23:59:36 2011
New Revision: 1203429

URL: http://svn.apache.org/viewvc?rev=1203429&view=rev
Log:
[LANG-775] [LANG-776] fix related bugs dealing with type variable inheritance

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java?rev=1203429&r1=1203428&r2=1203429&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java
Thu Nov 17 23:59:36 2011
@@ -216,9 +216,9 @@ public class TypeUtils {
                 toClass, typeVarAssigns);
 
         // now to check each type argument
-        for (Map.Entry<TypeVariable<?>, Type> entry : toTypeVarAssigns.entrySet())
{
-            Type toTypeArg = entry.getValue();
-            Type fromTypeArg = fromTypeVarAssigns.get(entry.getKey());
+        for (TypeVariable<?> var : toTypeVarAssigns.keySet()) {
+            Type toTypeArg = unrollVariableAssignments(var, toTypeVarAssigns);
+            Type fromTypeArg = unrollVariableAssignments(var, fromTypeVarAssigns);
 
             // parameters must either be absent from the subject type, within
             // the bounds of the wildcard type, or be an exact match to the
@@ -234,6 +234,19 @@ public class TypeUtils {
         return true;
     }
 
+    private static Type unrollVariableAssignments(TypeVariable<?> var, Map<TypeVariable<?>,
Type> typeVarAssigns) {
+        Type result;
+        do {
+            result = typeVarAssigns.get(var);
+            if (result instanceof TypeVariable<?> && !result.equals(var)) {
+                var = (TypeVariable<?>) result;
+                continue;
+            }
+            break;
+        } while (true);
+        return result;
+    }
+
     /**
      * <p> Checks if the subject type may be implicitly cast to the target
      * generic array type following the Java generics rules. </p>
@@ -658,8 +671,8 @@ public class TypeUtils {
         HashMap<TypeVariable<?>, Type> typeVarAssigns = subtypeVarAssigns ==
null ? new HashMap<TypeVariable<?>, Type>()
                 : new HashMap<TypeVariable<?>, Type>(subtypeVarAssigns);
 
-        // no arguments for the parameters, or target class has been reached
-        if (cls.getTypeParameters().length > 0 || toClass.equals(cls)) {
+        // has target class been reached?
+        if (toClass.equals(cls)) {
             return typeVarAssigns;
         }
 



Mime
View raw message