[hibernate-issues] [Hibernate-JIRA] Resolved: (HV-492) Validation of CGLIB enhanced Objects always return null
Hardy Ferentschik (JIRA)
noreply at atlassian.com
Tue Sep 27 11:50:35 EDT 2011
[ http://opensource.atlassian.com/projects/hibernate/browse/HV-492?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Hardy Ferentschik resolved HV-492.
----------------------------------
Resolution: Rejected
> Validation of CGLIB enhanced Objects always return null
> -------------------------------------------------------
>
> Key: HV-492
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-492
> Project: Hibernate Validator
> Issue Type: Bug
> Affects Versions: 4.1.0.Final, 4.2.0.Beta2
> Environment: Hibernate Validator 4.1.0-final and 4.2.0-BETA2, cglib 2.2
> Reporter: Christian Fehmer
>
> A validation of a cglib enhanced object will always validate "null".
> The validator (i tested it with an custom validator) always gets "null" as the value in the isValid method. The cglib enhanced object has a field "selection" and a getter/setter pair for this field. The hibernate validator uses the org.hibernate.validator.util.ReflectionHelper to access the field selection directly. That fails on a cglib enhanced object.
> My workaround for now: I replaced the org.hibernate.validator.util.ReflectionHelper.getValue method. When object is a cglib enhanced object i invoke the getter method instead of accessing the field directly.
> replaced method:
> {code}
> public static Object getValue(Member member, Object object) {
> Object value = null;
> if (member instanceof Method) {
> ...
> } else if (member instanceof Field) {
> // FIX: use getter method on cglib fields
> if (object.getClass().getName().contains("$$")) {
> String methodName = member.getName();
> methodName = "get"+ String.valueOf(methodName.charAt(0)).toUpperCase()+ methodName.substring(1);
> try {
> Method method = member.getDeclaringClass().getMethod(
> methodName);
> method.setAccessible(true);
> value = method.invoke(object);
> } catch (Exception e) {
> throw new ValidationException("Unable to access "
> + methodName, e);
> }
> } else {
> ...
> }
> }
> return value;
> }
> {code}
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list