You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@bval.apache.org by "Matt Benson (JIRA)" <ji...@apache.org> on 2012/09/16 19:17:07 UTC

[jira] [Updated] (BVAL-82) Validation of inherited methods causes ValidationException

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

Matt Benson updated BVAL-82:
----------------------------

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

{code}
  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);
    }
{code}

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.

{code}
  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 ###
{code}

  was:
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 ###


    
> Validation of inherited methods causes ValidationException
> ----------------------------------------------------------
>
>                 Key: BVAL-82
>                 URL: https://issues.apache.org/jira/browse/BVAL-82
>             Project: BVal
>          Issue Type: Bug
>          Components: method validation
>    Affects Versions: 0.1-incubating, 0.2-incubating, 0.3-incubating, 0.4
>            Reporter: Daniel Drachau
>            Assignee: Mohammad Nour
>             Fix For: 0.5
>
>
> MethodValidationImpl throws an exception if it tries to verify an inherited method (definition in the abstract superclass).
> {code}
>   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);
>     }
> {code}
> 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.
> {code}
>   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 ###
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira