Revision: 1172
          http://stripes.svn.sourceforge.net/stripes/?rev=1172&view=rev
Author:   bengunter
Date:     2009-10-19 20:03:00 +0000 (Mon, 19 Oct 2009)

Log Message:
-----------
Fixed STS-669: Spring injection problem when having private fields with the 
same name in parent and child classes. Added unit tests. DI should be done on 
fields in a superclass, even if a subclass declares a field with the same name.

Modified Paths:
--------------
    branches/1.5.x/stripes/src/net/sourceforge/stripes/util/ReflectUtil.java
    
branches/1.5.x/tests/src/net/sourceforge/stripes/integration/spring/SpringHelperTests.java

Modified: 
branches/1.5.x/stripes/src/net/sourceforge/stripes/util/ReflectUtil.java
===================================================================
--- branches/1.5.x/stripes/src/net/sourceforge/stripes/util/ReflectUtil.java    
2009-10-19 17:33:27 UTC (rev 1171)
+++ branches/1.5.x/stripes/src/net/sourceforge/stripes/util/ReflectUtil.java    
2009-10-19 20:03:00 UTC (rev 1172)
@@ -260,26 +260,22 @@
     }
 
     /**
-     * Fetches all fields of all access types from the supplied class and super
-     * classes. Fieldss that have been overridden in the inheritance hierarchy 
are
-     * only returned once, using the instance lowest down the hierarchy.
-     *
+     * Fetches all fields of all access types from the supplied class and 
super classes.
+     * 
      * @param clazz the class to inspect
      * @return a collection of fields
      */
     public static Collection<Field> getFields(Class<?> clazz) {
-        Map<String,Field> fields = new HashMap<String, Field>();
+        List<Field> fields = new ArrayList<Field>();
         while (clazz != null) {
             for (Field field : clazz.getDeclaredFields()) {
-                if ( !fields.containsKey(field.getName()) ) {
-                    fields.put(field.getName(), field);
-                }
+                fields.add(field);
             }
 
             clazz = clazz.getSuperclass();
         }
 
-        return fields.values();
+        return fields;
     }
 
     /**

Modified: 
branches/1.5.x/tests/src/net/sourceforge/stripes/integration/spring/SpringHelperTests.java
===================================================================
--- 
branches/1.5.x/tests/src/net/sourceforge/stripes/integration/spring/SpringHelperTests.java
  2009-10-19 17:33:27 UTC (rev 1171)
+++ 
branches/1.5.x/tests/src/net/sourceforge/stripes/integration/spring/SpringHelperTests.java
  2009-10-19 20:03:00 UTC (rev 1172)
@@ -273,4 +273,42 @@
         Assert.assertNotNull(target.number3);
         Assert.assertNotNull(target.number4);
     }
+
+    ///////////////////////////////////////////////////////////////////////////
+
+    public static class HiddenPrivateFieldTarget1 {
+        @SpringBean private TestBean a;
+        @SpringBean TestBean b;
+        @SpringBean protected TestBean c;
+        @SpringBean public TestBean d;
+        public TestBean getA1() { return a; }
+        public TestBean getB1() { return b; }
+        public TestBean getC1() { return c; }
+        public TestBean getD1() { return d; }
+    }
+
+    public static class HiddenPrivateFieldTarget2 extends 
HiddenPrivateFieldTarget1 {
+        @SpringBean private TestBean a;
+        @SpringBean TestBean b;
+        @SpringBean protected TestBean c;
+        @SpringBean public TestBean d;
+        public TestBean getA2() { return a; }
+        public TestBean getB2() { return b; }
+        public TestBean getC2() { return c; }
+        public TestBean getD2() { return d; }
+    }
+
+    @Test(groups = "fast")
+    public void testHiddenFields() {
+        HiddenPrivateFieldTarget2 target = new HiddenPrivateFieldTarget2();
+        SpringHelper.injectBeans(target, ctx);
+        Assert.assertNotNull(target.getA1());
+        Assert.assertNotNull(target.getA2());
+        Assert.assertNotNull(target.getB1());
+        Assert.assertNotNull(target.getB2());
+        Assert.assertNotNull(target.getC1());
+        Assert.assertNotNull(target.getC2());
+        Assert.assertNotNull(target.getD1());
+        Assert.assertNotNull(target.getD2());
+    }
 }
\ No newline at end of file


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to