JDK bug in bean introspection prevents Stripes validation
---------------------------------------------------------
Key: STS-664
URL: http://www.stripesframework.org/jira/browse/STS-664
Project: Stripes
Issue Type: Bug
Components: Validation
Affects Versions: Release 1.5.1
Reporter: Sebastian Beigel
I think I found a problem that we talked about 2 years ago (in a different
context though) on the mailing list. Stripes is using java.beans.Introspector
in DefaultValidationMetadataProvider to collect the validation information.
Unfortunately, there is (still) a bug in the (stable) JDK(s): bean
introspection doesn't consider generics [1]. Seems it is fixed in version 7 :)
Say I have a parameterized BaseAction like this:
public abstract class AbstractCRUDAction<T> implements ActionBean {
private T model;
public T getModel{...}
public void setModel(T model) {...}
...
}
and an implementation like:
public class UserAction extends AbstractCRUDAction<User> {
@ValidateNested(...)
@Override
public User getModel() { return super.getModel(); }
...
}
The model (a User object) is not validated. Having a look in the debugger shows
that the bean introspection returns the wrong read method for "model", i.e. the
base-class method (containing no annotations of course).
We had the same problem in Oct 2006 on the mailing list [2] an Tim found a
workaround:
>From reading up it would appear that the compiler generates a bridge method
>for any concrete implementation of an interface method that involves a type
>variable that is parameterized in the class. [...]
A bit of poking shows that you can actually get around this by basically doing:
Method m = pd.getReadMethod();
if (m.isBridge()) m = m.getDeclaringClass().getMethod(m.getName());
which returns the correct, non-bridge method. [...]
So I think it would be a good idea to include this line in
DefaultValidationMetadataProvider.loadForClass() to get the "right" getter
method. Otherwise it's no possible to add validation to generic ActionBean
properties.
What do you think?
Sebatian
References:
[1] http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6422403
[2] http://www.nabble.com/Re%3A-generics-interface-to6806773.html#a6806773
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://www.stripesframework.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development