commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r654273 - /commons/proper/lang/trunk/src/java/org/apache/commons/lang/reflect/FieldUtils.java
Date Wed, 07 May 2008 21:06:49 GMT
Author: mbenson
Date: Wed May  7 14:06:48 2008
New Revision: 654273

URL: http://svn.apache.org/viewvc?rev=654273&view=rev
Log:
use existing API to get all interfaces

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/reflect/FieldUtils.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/reflect/FieldUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/reflect/FieldUtils.java?rev=654273&r1=654272&r2=654273&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/reflect/FieldUtils.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/reflect/FieldUtils.java Wed
May  7 14:06:48 2008
@@ -18,6 +18,9 @@
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
+import java.util.Iterator;
+
+import org.apache.commons.lang.ClassUtils;
 
 /**
  * Utilities for working with fields by reflection. Adapted and refactored
@@ -113,27 +116,21 @@
         // incase there is a public supersuperclass field hidden by a private/package
         // superclass field.
         Field match = null;
-        for (Class acls = cls; acls != null; acls = acls.getSuperclass()) {
-            Class[] ints = acls.getInterfaces();
-            for (int i = 0; i < ints.length; i++) {
-                // getField is fine here, because everything is public, and thus it works
-                try {
-                    Field test = ints[i].getField(fieldName);
-                    if (match != null) {
-                        if (match.getDeclaringClass().equals(test.getDeclaringClass())) {
-                            continue;
-                        }
-                        throw new IllegalArgumentException(
-                                "Reference to field "
-                                        + fieldName
-                                        + " is ambiguous relative to "
-                                        + cls
-                                        + "; a matching field exists on two or more parent
interfaces.");
-                    }
-                    match = test;
-                } catch (NoSuchFieldException ex) {
-                    // ignore
+        for (Iterator intf = ClassUtils.getAllInterfaces(cls).iterator(); intf
+                .hasNext();) {
+            try {
+                Field test = ((Class) intf.next()).getField(fieldName);
+                if (match != null) {
+                    throw new IllegalArgumentException(
+                            "Reference to field "
+                                    + fieldName
+                                    + " is ambiguous relative to "
+                                    + cls
+                                    + "; a matching field exists on two or more parent interfaces.");
                 }
+                match = test;
+            } catch (NoSuchFieldException ex) {
+                // ignore
             }
         }
         return match;



Mime
View raw message