@Validate annotation on boolean property isXyz() fails
------------------------------------------------------
Key: STS-425
URL: http://mc4j.org/jira/browse/STS-425
Project: Stripes
Issue Type: Bug
Components: Validation
Affects Versions: Release 1.4.3, Release 1.5
Reporter: Frederic Daoud
Assigned To: Tim Fennell
Priority: Minor
@Validate annotations work on fields, getters and setters.
For a boolean property xyz, the JavaBean convention is to name the getter
"isXyz".
Doing so makes the annotation fail, because Stripes assumes that the method
prefix is of length 3 (get/set). In the example above, the property name ends
up being "yz".
The core of the problem is in the "getPropertyName" method of the
DefaultActionBeanPropertyBinder class:
net.sourceforge.stripes.controller.DefaultActionBeanPropertyBinder
563: protected String getPropertyName(String methodName) {
564: return methodName.substring(3,4).toLowerCase() +
methodName.substring(4);
565: }
This assumes that the property name is the method name with the first 3
characters removed (get/set), which causes problems when the method name is
"isXyz".
Used in the "processClassAnnotations" method of the same class:
(lines 173-192):
Validate validation = method.getAnnotation(Validate.class);
if (validation != null) {
String fieldName = getPropertyName(method.getName()); // *
-- here -- *
fieldValidations.put(fieldName, validation);
}
ValidateNestedProperties nested =
method.getAnnotation(ValidateNestedProperties.class);
if (nested != null) {
String fieldName = getPropertyName(method.getName()); // *
-- here -- *
Validate[] validations = nested.value();
for (Validate nestedValidate : validations) {
if ( "".equals(nestedValidate.field()) ) {
log.warn("Nested validation used without field name: ",
validation);
}
else {
fieldValidations.put(fieldName + "." +
nestedValidate.field(),
nestedValidate);
}
}
}
Easy workaround by annotating setter, field, or naming method getXyz() instead
of isXyz(); nevertheless, pointing out this bug which could cause hard-to-find
bugs to the unsuspecting developer.
Thanks,
Freddy
--
Frederic Daoud
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://mc4j.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development