0 Replies Latest reply on Sep 28, 2010 7:07 PM by 667384

    Unable to get annotations for method arguments on overriding subclasses

      Hi all,
      I'm implementing a JSR-303 aspect that intercepts calls to my data access tier and my business tier to validate input before the target method is invoked. I have the following annotation.
      @Target({ PARAMETER })
      public @interface Check {
           Class<?>[] groups() default { };
      Here is my abstract class
      public abstract class BaseJdoDao<EntityType extends Entity<KeyType>, KeyType>
                extends JdoDaoSupport implements IBaseDao<EntityType, KeyType> {
           public void save(@Check EntityType model) {
      And it's subclass

      public class SpiderUpdateDao extends BaseJdoDao<SpiderUpdate, UUID> implements
                ISpiderUpdateDao {
            * (non-Javadoc)
            * @see
            * com.spidertracks.aviator.dataaccess.IBaseDao#save(com.spidertracks.aviator
            * .model.Entity)
           public void save(@Check SpiderUpdate model) {
      Now, when I get a Method instance off the class SpiderUpdateDao with the following call
      targetMethod = runtimeClass.getMethod(sig.getName(), sig.getParameterTypes());
      I'm returned a Method instance on class SpiderUpdateDao that points to the method above. Then, when I call this method
      Annotation[][] annotations = targetMethod.getParameterAnnotations();
      I'm returned 1 element in the first dimension, and 0 elements in the second dimension. As you can clearly see, my subclass is annotated. I know that annotations aren't inherited by default, so I assumed (apparently incorrectly) that if a user explicitly annotates a subclass's overriding method, I would still be able to retrieve those annotations. Is this not the case? If not, how do I go about getting these annotations at run time? I've also tried adding another annotation so the overriding method has 2 annotations on the parameters to test if it's an issue with the method signature being exactly the same as the parent class. Unfortunately I'm always returned 0 annotations in this case as well. How can I get the annotations on my class at runtime? As you can see, my annotation is set to have a run time retention. I'm running the latest JDK 1.6. I receive this behavior both on OS X 10.6 and on Ubuntu 10.04 with Sun JDK 1.6.

      Thanks in advance,