Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4738

AnnotationValidationInterceptor : NullPointerException when method is null

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.3.24
    • Fix Version/s: 2.5.10
    • Component/s: Core Interceptors
    • Labels:
      None

      Description

      In AnnotationValidationInterceptor class method can be null and method.getName() throws a NullPointerException

      Why only in devMode a NoSuchMethodException is thrown ?

          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;
          }
      
      
      

        Attachments

          Activity

            People

            • Assignee:
              lukaszlenart Lukasz Lenart
              Reporter:
              fustaki Lorenzo Bernacchioni
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: