Skip to content

Commit a37a25c

Browse files
committed
Merge pull request #1 from csabapalfi/master
Workaround for a bug in java.beans.Introspector
2 parents cfe7cce + da13048 commit a37a25c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

JavaBeanTester.java

+27
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public static <T> void test(final Class<T> clazz, final String... skipThese) thr
3232
continue nextProp;
3333
}
3434
}
35+
findBooleanIsMethods(clazz, prop);
3536
final Method getter = prop.getReadMethod();
3637
final Method setter = prop.getWriteMethod();
3738

@@ -123,5 +124,31 @@ private static Object buildValue(Class<?> clazz) throws InstantiationException,
123124
return null; // for the compiler
124125
}
125126
}
127+
128+
/**
129+
* Hunt down missing Boolean read method if needed as Introspector cannot find 'is' getters
130+
* for Boolean type properties.
131+
*
132+
* @param clazz
133+
* the type being introspected
134+
* @param descriptor
135+
* the property descriptor found so far
136+
*/
137+
public static <T> void findBooleanIsMethods(Class<T> clazz, PropertyDescriptor descriptor) throws IntrospectionException {
138+
if ( needToFindReadMethod(descriptor) ) {
139+
findTheReadMethod(descriptor, clazz);
140+
}
141+
}
142+
143+
private static boolean needToFindReadMethod(PropertyDescriptor property) {
144+
return property.getReadMethod() == null && property.getPropertyType() == Boolean.class;
145+
}
146+
147+
private static <T> void findTheReadMethod(PropertyDescriptor descriptor, Class<T> clazz) {
148+
try {
149+
PropertyDescriptor pd = new PropertyDescriptor(descriptor.getName(), clazz);
150+
descriptor.setReadMethod(pd.getReadMethod());
151+
} catch (IntrospectionException e) {}
152+
}
126153
}
127154

0 commit comments

Comments
 (0)