Author: epbernard
Date: 2009-05-04 11:34:08 -0400 (Mon, 04 May 2009)
New Revision: 16506
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java
Log:
HV-149 ReflectionHelper.containsMethod ignores "is" methods
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java 2009-05-04
12:42:25 UTC (rev 16505)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java 2009-05-04
15:34:08 UTC (rev 16506)
@@ -544,12 +544,17 @@
private <T> Object collectMetaConstraintsForPath(Class<T> clazz, Object
value, PropertyIterator propertyIter, Set<MetaConstraint<T, ?>>
metaConstraints) {
propertyIter.split();
+ final BeanMetaData<T> metaData = getBeanMetaData( clazz );
if ( !propertyIter.hasNext() ) {
- if ( !ReflectionHelper.containsMember( clazz, propertyIter.getHead() ) ) {
+ //use metadata first as ReflectionHelper#containsMember is slow
+ //TODO store some metadata here?
+ if ( metaData.getPropertyDescriptor( propertyIter.getHead() ) == null
+ && !ReflectionHelper.containsMember( clazz, propertyIter.getHead() ) ) {
+ //TODO better error report
throw new IllegalArgumentException( "Invalid property path." );
}
- List<MetaConstraint<T, ? extends Annotation>> metaConstraintList =
getBeanMetaData( clazz ).geMetaConstraintList();
+ List<MetaConstraint<T, ? extends Annotation>> metaConstraintList =
metaData.geMetaConstraintList();
for ( MetaConstraint<T, ?> metaConstraint : metaConstraintList ) {
if ( metaConstraint.getPropertyName().equals( propertyIter.getHead() ) ) {
metaConstraints.add( metaConstraint );
@@ -557,7 +562,7 @@
}
}
else {
- List<Member> cascadedMembers = getBeanMetaData( clazz ).getCascadedMembers();
+ List<Member> cascadedMembers = metaData.getCascadedMembers();
for ( Member m : cascadedMembers ) {
if ( ReflectionHelper.getPropertyName( m ).equals( propertyIter.getHead() ) ) {
Type type = ReflectionHelper.typeOf( m );
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java 2009-05-04
12:42:25 UTC (rev 16505)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java 2009-05-04
15:34:08 UTC (rev 16506)
@@ -394,7 +394,15 @@
*/
public static boolean containsMethod(Class<?> clazz, String methodName) {
try {
- clazz.getMethod( "get" + methodName.substring( 0, 1 ).toUpperCase() +
methodName.substring( 1 ) );
+ char string[] = methodName.toCharArray();
+ string[0] = Character.toUpperCase( string[0] );
+ methodName = new String( string );
+ try {
+ clazz.getMethod( "get" + methodName );
+ }
+ catch ( NoSuchMethodException e ) {
+ clazz.getMethod( "is" + methodName );
+ }
return true;
}
catch ( NoSuchMethodException e ) {
Show replies by date