Uploaded image for project: 'BVal'
  1. BVal
  2. BVAL-82

Validation of inherited methods causes ValidationException

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • 0.1-incubating, 0.2-incubating, 0.3-incubating, 0.4, 0.5
    • 1.0
    • method validation
    • None

    Description

      MethodValidationImpl throws an exception if it tries to verify an inherited method (definition in the abstract superclass).

        public <T> Set<ConstraintViolation<T>> validateParameter(Class<T> clazz, Method method,
                                                                 Object parameter,
                                                                 int parameterIndex,
                                                                 Class<?>... groupArray) {
          MethodBeanDescriptorImpl beanDesc =
              (MethodBeanDescriptorImpl) getConstraintsForClass(clazz);
          MethodDescriptorImpl methodDescriptor =
              (MethodDescriptorImpl) beanDesc.getConstraintsForMethod(method);
          if ( methodDescriptor == null ) {
      -->        throw new ValidationException("Method " + method + " doesn't belong to class " + clazz);
          }
      

      a possible fix might be to collect the method declarations of the parent classes as well (in the MethodValidatorMetaBeanFactory). I cannot decide if this really fix the problem or just one symptom.

        private void buildMethodConstraints(MethodBeanDescriptorImpl beanDesc)
            throws InvocationTargetException, IllegalAccessException {
          beanDesc.setMethodConstraints(new HashMap<Method, MethodDescriptor>());
      ### new ###
          ArrayList<Method> methods = new ArrayList<Method>();
          for (Method m : beanDesc.getMetaBean().getBeanClass().getDeclaredMethods()) {
            methods.add(m);
          }
          Class clazz = beanDesc.getMetaBean().getBeanClass();
          while (clazz.getSuperclass() != null) {
            clazz = clazz.getSuperclass();
            for (Method m : clazz.getDeclaredMethods()) {
              methods.add(m);
            }
          }
      
          for (Method method : methods) {
      ### end new ###
      

      Attachments

        Activity

          People

            mnour Mohammad Nour El-Din
            ddrachau Daniel Drachau
            Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: