Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: Release 1.5.1
-
Fix Version/s: Release 1.5.2, Release 1.6
-
Component/s: Validation
-
Labels:None
Description
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
Fixed as suggested for 1.5.2 and 1.6.