[ 
https://issues.apache.org/jira/browse/WW-4738?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Lorenzo Bernacchioni updated WW-4738:
-------------------------------------
    Description: 
In {{AnnotationValidationInterceptor}} class {{method}} can be null and 
{{method.getName()}} throws a NullPointerException

Why only when {{devMode}} is true a {{NoSuchMethodException}} is thrown ?

{code}
    protected String doIntercept(ActionInvocation invocation) throws Exception {

        Object action = invocation.getAction();
        if (action != null) {
            Method method = getActionMethod(action.getClass(), 
invocation.getProxy().getMethod());
            Collection<Method> annotatedMethods = 
AnnotationUtils.getAnnotatedMethods(action.getClass(), SkipValidation.class);
            if (annotatedMethods.contains(method))
                return invocation.invoke();

            //check if method overwites an annotated method
            Class clazz = action.getClass().getSuperclass();
            while (clazz != null) {
                annotatedMethods = AnnotationUtils.getAnnotatedMethods(clazz, 
SkipValidation.class);
                if (annotatedMethods != null) {
                    for (Method annotatedMethod : annotatedMethods) {
                        if (annotatedMethod.getName().equals(method.getName())
                                && 
Arrays.equals(annotatedMethod.getParameterTypes(), method.getParameterTypes())
                                && 
Arrays.equals(annotatedMethod.getExceptionTypes(), method.getExceptionTypes()))
                            return invocation.invoke();
                    }
                }
                clazz = clazz.getSuperclass();
            }
        }

        return super.doIntercept(invocation);
    }


    protected Method getActionMethod(Class actionClass, String methodName) 
throws NoSuchMethodException {
        Method method = null;
        try {
            method = actionClass.getMethod(methodName, new Class[0]);
        } catch (NoSuchMethodException e) {
            // hmm -- OK, try doXxx instead
            try {
                String altMethodName = "do" + methodName.substring(0, 
1).toUpperCase() + methodName.substring(1);
                method = actionClass.getMethod(altMethodName, new Class[0]);
            } catch (NoSuchMethodException e1) {
                // throw the original one
                if (devMode) {
                    throw e;
                }
            }
        }
        return method;
    }


{code}

  was:
In {{AnnotationValidationInterceptor}} class {{method}} can be null and 
{{method.getName()}} throws a NullPointerException

{code}
    protected String doIntercept(ActionInvocation invocation) throws Exception {

        Object action = invocation.getAction();
        if (action != null) {
            Method method = getActionMethod(action.getClass(), 
invocation.getProxy().getMethod());
            Collection<Method> annotatedMethods = 
AnnotationUtils.getAnnotatedMethods(action.getClass(), SkipValidation.class);
            if (annotatedMethods.contains(method))
                return invocation.invoke();

            //check if method overwites an annotated method
            Class clazz = action.getClass().getSuperclass();
            while (clazz != null) {
                annotatedMethods = AnnotationUtils.getAnnotatedMethods(clazz, 
SkipValidation.class);
                if (annotatedMethods != null) {
                    for (Method annotatedMethod : annotatedMethods) {
                        if (annotatedMethod.getName().equals(method.getName())
                                && 
Arrays.equals(annotatedMethod.getParameterTypes(), method.getParameterTypes())
                                && 
Arrays.equals(annotatedMethod.getExceptionTypes(), method.getExceptionTypes()))
                            return invocation.invoke();
                    }
                }
                clazz = clazz.getSuperclass();
            }
        }

        return super.doIntercept(invocation);
    }
{code}


> AnnotationValidationInterceptor : NullPointerException when method is null
> --------------------------------------------------------------------------
>
>                 Key: WW-4738
>                 URL: https://issues.apache.org/jira/browse/WW-4738
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Interceptors
>    Affects Versions: 2.3.24
>            Reporter: Lorenzo Bernacchioni
>            Priority: Minor
>
> In {{AnnotationValidationInterceptor}} class {{method}} can be null and 
> {{method.getName()}} throws a NullPointerException
> Why only when {{devMode}} is true a {{NoSuchMethodException}} is thrown ?
> {code}
>     protected String doIntercept(ActionInvocation invocation) throws 
> Exception {
>         Object action = invocation.getAction();
>         if (action != null) {
>             Method method = getActionMethod(action.getClass(), 
> invocation.getProxy().getMethod());
>             Collection<Method> annotatedMethods = 
> AnnotationUtils.getAnnotatedMethods(action.getClass(), SkipValidation.class);
>             if (annotatedMethods.contains(method))
>                 return invocation.invoke();
>             //check if method overwites an annotated method
>             Class clazz = action.getClass().getSuperclass();
>             while (clazz != null) {
>                 annotatedMethods = AnnotationUtils.getAnnotatedMethods(clazz, 
> SkipValidation.class);
>                 if (annotatedMethods != null) {
>                     for (Method annotatedMethod : annotatedMethods) {
>                         if (annotatedMethod.getName().equals(method.getName())
>                                 && 
> Arrays.equals(annotatedMethod.getParameterTypes(), method.getParameterTypes())
>                                 && 
> Arrays.equals(annotatedMethod.getExceptionTypes(), 
> method.getExceptionTypes()))
>                             return invocation.invoke();
>                     }
>                 }
>                 clazz = clazz.getSuperclass();
>             }
>         }
>         return super.doIntercept(invocation);
>     }
>     protected Method getActionMethod(Class actionClass, String methodName) 
> throws NoSuchMethodException {
>         Method method = null;
>         try {
>             method = actionClass.getMethod(methodName, new Class[0]);
>         } catch (NoSuchMethodException e) {
>             // hmm -- OK, try doXxx instead
>             try {
>                 String altMethodName = "do" + methodName.substring(0, 
> 1).toUpperCase() + methodName.substring(1);
>                 method = actionClass.getMethod(altMethodName, new Class[0]);
>             } catch (NoSuchMethodException e1) {
>                 // throw the original one
>                 if (devMode) {
>                     throw e;
>                 }
>             }
>         }
>         return method;
>     }
> {code}



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

Reply via email to