1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
35
35
import java .util .Set ;
36
36
import java .util .TreeSet ;
37
37
38
+ import org .apache .commons .logging .Log ;
39
+ import org .apache .commons .logging .LogFactory ;
40
+
38
41
import static org .springframework .beans .PropertyDescriptorUtils .*;
39
42
40
43
/**
73
76
*/
74
77
class ExtendedBeanInfo implements BeanInfo {
75
78
79
+ private static final Log logger = LogFactory .getLog (ExtendedBeanInfo .class );
80
+
76
81
private final BeanInfo delegate ;
77
82
78
83
private final Set <PropertyDescriptor > propertyDescriptors =
@@ -94,14 +99,30 @@ class ExtendedBeanInfo implements BeanInfo {
94
99
public ExtendedBeanInfo (BeanInfo delegate ) throws IntrospectionException {
95
100
this .delegate = delegate ;
96
101
for (PropertyDescriptor pd : delegate .getPropertyDescriptors ()) {
97
- this .propertyDescriptors .add (pd instanceof IndexedPropertyDescriptor ?
98
- new SimpleIndexedPropertyDescriptor ((IndexedPropertyDescriptor ) pd ) :
99
- new SimplePropertyDescriptor (pd ));
102
+ try {
103
+ this .propertyDescriptors .add (pd instanceof IndexedPropertyDescriptor ?
104
+ new SimpleIndexedPropertyDescriptor ((IndexedPropertyDescriptor ) pd ) :
105
+ new SimplePropertyDescriptor (pd ));
106
+ }
107
+ catch (IntrospectionException ex ) {
108
+ // Probably simply a method that wasn't meant to follow the JavaBeans pattern...
109
+ if (logger .isDebugEnabled ()) {
110
+ logger .debug ("Ignoring invalid bean property '" + pd .getName () + "': " + ex .getMessage ());
111
+ }
112
+ }
100
113
}
101
114
MethodDescriptor [] methodDescriptors = delegate .getMethodDescriptors ();
102
115
if (methodDescriptors != null ) {
103
116
for (Method method : findCandidateWriteMethods (methodDescriptors )) {
104
- handleCandidateWriteMethod (method );
117
+ try {
118
+ handleCandidateWriteMethod (method );
119
+ }
120
+ catch (IntrospectionException ex ) {
121
+ // We're only trying to find candidates, can easily ignore extra ones here...
122
+ if (logger .isDebugEnabled ()) {
123
+ logger .debug ("Ignoring candidate write method [" + method + "]: " + ex .getMessage ());
124
+ }
125
+ }
105
126
}
106
127
}
107
128
}
@@ -131,15 +152,15 @@ public static boolean isCandidateWriteMethod(Method method) {
131
152
String methodName = method .getName ();
132
153
Class <?>[] parameterTypes = method .getParameterTypes ();
133
154
int nParams = parameterTypes .length ;
134
- return methodName .length () > 3 && methodName .startsWith ("set" ) && Modifier .isPublic (method .getModifiers ()) &&
155
+ return ( methodName .length () > 3 && methodName .startsWith ("set" ) && Modifier .isPublic (method .getModifiers ()) &&
135
156
(!void .class .isAssignableFrom (method .getReturnType ()) || Modifier .isStatic (method .getModifiers ())) &&
136
- (nParams == 1 || (nParams == 2 && parameterTypes [0 ].equals (int .class )));
157
+ (nParams == 1 || (nParams == 2 && parameterTypes [0 ].equals (int .class )))) ;
137
158
}
138
159
139
160
private void handleCandidateWriteMethod (Method method ) throws IntrospectionException {
140
161
int nParams = method .getParameterTypes ().length ;
141
162
String propertyName = propertyNameFor (method );
142
- Class <?> propertyType = method .getParameterTypes ()[nParams - 1 ];
163
+ Class <?> propertyType = method .getParameterTypes ()[nParams - 1 ];
143
164
PropertyDescriptor existingPd = findExistingPropertyDescriptor (propertyName , propertyType );
144
165
if (nParams == 1 ) {
145
166
if (existingPd == null ) {
0 commit comments