struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (WW-4744) AnnotationWorkflowInterceptor should supports non-public annotated methods
Date Tue, 21 Mar 2017 06:06:41 GMT

    [ https://issues.apache.org/jira/browse/WW-4744?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15934143#comment-15934143
] 

ASF GitHub Bot commented on WW-4744:
------------------------------------

Github user lukaszlenart commented on a diff in the pull request:

    https://github.com/apache/struts/pull/124#discussion_r107079461
  
    --- Diff: core/src/main/java/com/opensymphony/xwork2/util/AnnotationUtils.java ---
    @@ -150,25 +166,32 @@ public static void addAllInterfaces(Class clazz, List<Class>
allInterfaces) {
          * @return the annotation found, or {@code null} if none
          */
         public static <A extends Annotation> A findAnnotation(Method method, Class<A>
annotationType) {
    -        A result = getAnnotation(method, annotationType);
    -        Class<?> clazz = method.getDeclaringClass();
    +        AnnotationCacheKey cacheKey = new AnnotationCacheKey(method, annotationType);
    +        A result = (A) findAnnotationCache.get(cacheKey);
             if (result == null) {
    -            result = searchOnInterfaces(method, annotationType, clazz.getInterfaces());
    -        }
    -        while (result == null) {
    -            clazz = clazz.getSuperclass();
    -            if (clazz == null || clazz.equals(Object.class)) {
    -                break;
    -            }
    -            try {
    -                Method equivalentMethod = clazz.getDeclaredMethod(method.getName(), method.getParameterTypes());
    -                result = getAnnotation(equivalentMethod, annotationType);
    -            } catch (NoSuchMethodException ex) {
    -                // No equivalent method found
    -            }
    +            result = getAnnotation(method, annotationType);
    +            Class<?> clazz = method.getDeclaringClass();
                 if (result == null) {
                     result = searchOnInterfaces(method, annotationType, clazz.getInterfaces());
                 }
    +            while (result == null) {
    +                clazz = clazz.getSuperclass();
    +                if (clazz == null || clazz.equals(Object.class)) {
    +                    break;
    +                }
    +                try {
    +                    Method equivalentMethod = clazz.getDeclaredMethod(method.getName(),
method.getParameterTypes());
    +                    result = getAnnotation(equivalentMethod, annotationType);
    +                } catch (NoSuchMethodException ex) {
    +                    // No equivalent method found
    --- End diff --
    
    no need to LOG this exception?


> AnnotationWorkflowInterceptor should supports non-public annotated methods
> --------------------------------------------------------------------------
>
>                 Key: WW-4744
>                 URL: https://issues.apache.org/jira/browse/WW-4744
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Core Interceptors
>            Reporter: zhouyanming
>             Fix For: 2.5.next
>
>
> {code:java}
> @Before
> protected String prepare(){
>     //TODO
>     return null;
> }
> {code}
> [https://github.com/apache/struts/blob/master/core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/AnnotationWorkflowInterceptor.java#L115]
> {code:java}
> List<Method> methods = new ArrayList<>(AnnotationUtils.getAnnotatedMethods(action.getClass(),
Before.class));
> {code}
> [https://github.com/apache/struts/blob/master/core/src/main/java/com/opensymphony/xwork2/util/AnnotationUtils.java#L123]
> {code:java}
> for (Method m : clazz.getMethods()) 
> {code}
> clazz.getMethods() only return public methods, so method "prepare" will be excluded,
and protected modifier is a good practice for intercept method.We should improve AnnotationUtils.getAnnotatedMethods()
to return all methods. Perhaps use an ConcurrentHashMap as cache is much better.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message