Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Ignore non-prop 'set' methods in ExtendedBeanInfo

Previously, ExtendedBeanInfo would attempt to process methods named
exactly 'set'.  JavaBeans properties must have at least one character
following the 'set' prefix in order to qualify, and this is now
respected by EBI.

Thanks to Rob Winch for the patch fixing this problem.

Issue: SPR-8175

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4178 50f2f4bb-b051-0410-bef5-90022cba6387
  • Loading branch information...
commit 8dedf111bcf08af967c2de00b3e1ee4e99979533 1 parent 772aee7
Chris Beams authored April 05, 2011
6  org.springframework.beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java
@@ -82,6 +82,9 @@ public ExtendedBeanInfo(BeanInfo delegate) throws IntrospectionException {
82 82
 			// is the method a NON-INDEXED setter? ignore return type in order to capture non-void signatures
83 83
 			if (method.getName().startsWith("set") && method.getParameterTypes().length == 1) {
84 84
 				String propertyName = propertyNameFor(method);
  85
+				if(propertyName.length() == 0) {
  86
+					continue ALL_METHODS;
  87
+				}
85 88
 				for (PropertyDescriptor pd : delegate.getPropertyDescriptors()) {
86 89
 					Method readMethod = pd.getReadMethod();
87 90
 					Method writeMethod = pd.getWriteMethod();
@@ -109,6 +112,9 @@ public ExtendedBeanInfo(BeanInfo delegate) throws IntrospectionException {
109 112
 			// is the method an INDEXED setter? ignore return type in order to capture non-void signatures
110 113
 			if (method.getName().startsWith("set") && method.getParameterTypes().length == 2 && method.getParameterTypes()[0].equals(int.class)) {
111 114
 				String propertyName = propertyNameFor(method);
  115
+				if(propertyName.length() == 0) {
  116
+					continue ALL_METHODS;
  117
+				}
112 118
 				DELEGATE_PD:
113 119
 				for (PropertyDescriptor pd : delegate.getPropertyDescriptors()) {
114 120
 					if (!(pd instanceof IndexedPropertyDescriptor)) {
21  org.springframework.beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java
@@ -19,8 +19,6 @@
19 19
 import static org.hamcrest.CoreMatchers.equalTo;
20 20
 import static org.hamcrest.CoreMatchers.instanceOf;
21 21
 import static org.hamcrest.CoreMatchers.is;
22  
-import static org.hamcrest.CoreMatchers.notNullValue;
23  
-import static org.hamcrest.CoreMatchers.nullValue;
24 22
 import static org.hamcrest.Matchers.greaterThan;
25 23
 import static org.hamcrest.Matchers.lessThan;
26 24
 import static org.junit.Assert.assertThat;
@@ -32,7 +30,6 @@
32 30
 import java.beans.Introspector;
33 31
 import java.beans.PropertyDescriptor;
34 32
 
35  
-import org.junit.Ignore;
36 33
 import org.junit.Test;
37 34
 import org.springframework.beans.ExtendedBeanInfo.PropertyDescriptorComparator;
38 35
 
@@ -485,6 +482,23 @@ public void setFoo(String foo) { }
485 482
 		assertThat(hasWriteMethodForProperty(ebi, "foo"), is(true));
486 483
 	}
487 484
 
  485
+	/**
  486
+	 * Ensures that an empty string is not passed into a PropertyDescriptor constructor. This
  487
+	 * could occur when handling ArrayList.set(int,Object)
  488
+	 */
  489
+	@Test
  490
+	public void emptyPropertiesIgnored() throws IntrospectionException {
  491
+		@SuppressWarnings("unused") class C {
  492
+			public Object set(Object o) { return null; }
  493
+			public Object set(int i, Object o) { return null; }
  494
+		}
  495
+
  496
+		BeanInfo bi = Introspector.getBeanInfo(C.class);
  497
+		ExtendedBeanInfo ebi = new ExtendedBeanInfo(bi);
  498
+
  499
+		assertThat(ebi.getPropertyDescriptors(), equalTo(bi.getPropertyDescriptors()));
  500
+	}
  501
+
488 502
 	@Test
489 503
 	public void propertyCountsMatch() throws IntrospectionException {
490 504
 		BeanInfo bi = Introspector.getBeanInfo(TestBean.class);
@@ -545,7 +559,6 @@ public void propertyDescriptorComparator() throws IntrospectionException {
545 559
 		assertThat(c.compare(new PropertyDescriptor("a", null, null), new PropertyDescriptor("A", null, null)), greaterThan(0));
546 560
 	}
547 561
 
548  
-
549 562
 	private boolean hasWriteMethodForProperty(BeanInfo beanInfo, String propertyName) {
550 563
 		for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
551 564
 			if (pd.getName().equals(propertyName)) {

0 notes on commit 8dedf11

Please sign in to comment.
Something went wrong with that request. Please try again.