struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lorenzo Bernacchioni (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (WW-4738) AnnotationValidationInterceptor : NullPointerException when method is null
Date Fri, 03 Feb 2017 12:51:51 GMT

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

Lorenzo Bernacchioni edited comment on WW-4738 at 2/3/17 12:51 PM:
-------------------------------------------------------------------

Given this configuration
{code:xml|title=struts.xml|borderStyle=solid}
<action name="MyAction!*" method="{1}" class="com.myproject.MyAction">
	....
</action>
{code}
If method {{xxx()}} is not defined in {{MyAction.java}} the URI {{/MyAction!xxx}} generates
a {{NullPointerException}}.
I find {{NoSuchMethodException}} more appropriate (it can be easily routed to a 404 via {{<global-exception-mappings>}}
while NullPointerExceptions are usually meant to be unexpected problems to be solved)



was (Author: fustaki):
Given this configuration
{code:xml|title=struts.xml|borderStyle=solid}
<action name="MyAction!*" method="{1}" class="com.myproject.MyAction">
	....
</action>
{code}
If method {{xxx()}} is not defined in {{MyAction.java}} the URI {{/MyAction!xxx}} generates
a {{NullPointerException}}.
I find {{NoSuchMethodException}} more appropriate (it can be easily routed to a 404 via {{exception-mappings}}
while NullPointerExceptions are usually meant to be unexpected problems to be solved)


> 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
>             Fix For: 2.5.next
>
>
> In {{AnnotationValidationInterceptor}} class {{method}} can be null and {{method.getName()}}
throws a NullPointerException
> Why only in {{devMode}} 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)

Mime
View raw message