felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1350680 - /felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
Date Fri, 15 Jun 2012 16:24:54 GMT
Author: pderop
Date: Fri Jun 15 16:24:54 2012
New Revision: 1350680

URL: http://svn.apache.org/viewvc?rev=1350680&view=rev
Log:
Modified getField(Class, String) method in order to be able to introspect 
private fields from parent class.

Modified:
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java?rev=1350680&r1=1350679&r2=1350680&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
(original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
Fri Jun 15 16:24:54 2012
@@ -325,9 +325,22 @@ public abstract class ComponentTestBase
 
     protected static Field getField( Class<?> type, String fieldName ) throws NoSuchFieldException
     {
-        Field field = type.getDeclaredField( fieldName );
-        field.setAccessible( true );
-        return field;
+        Class<?> clazz = type;
+        while (clazz != null)
+        {
+            Field[] fields = clazz.getDeclaredFields();
+            for (int i = 0; i < fields.length; i++)
+            {
+                Field field = fields[i];
+                if (field.getName().equals(fieldName))
+                {
+                    field.setAccessible( true );
+                    return field;
+                }
+            }
+            clazz = clazz.getSuperclass();
+        }
+        throw new NoSuchFieldException(fieldName);        
     }
 
 



Mime
View raw message