[
https://issues.apache.org/jira/browse/BVAL-45?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12868233#action_12868233
]
Carlos Vara commented on BVAL-45:
---------------------------------
Also, I would like to explain this a little more:
- Only method annotations that clash are return value annotations (I forgot to
add this detail). So for example, this:
public class Person {
private String name;
@NotNull
public String getName() {
return name;
}
public void setName(@NotNull String name) {
this.name = name;
}
}
Doesn't conflict and won't throw any exception. There is an annotated method
but its return value is not annotated, so it isn't detected as an invalid
getter when validating a person bean. Only something like this:
public class Person {
private String name;
@NotNull
public String getName() {
return name;
}
@NotNull
public String invalidGetterName() {
return name.toLowerCase();
}
}
Would fail. Which is arguably a good thing.
- I guess for most common cases this is OK. I for one am using method
validation and have had no problems with this patch, as the classes in which I
validate the methods are not "domain" classes so never get validated like
beans. Also, the ability to still have method validation for constructors and
setters (and every method parameters) leaves the door quite open to overcome
the limitation imposed by the spec.
> ValidationException must be thrown when validating a bean with an annotated
> method which isn't a valid getter
> -------------------------------------------------------------------------------------------------------------
>
> Key: BVAL-45
> URL: https://issues.apache.org/jira/browse/BVAL-45
> Project: BeanValidation
> Issue Type: Bug
> Components: jsr303
> Affects Versions: 0.1-incubating
> Reporter: Carlos Vara
> Attachments: bval-jsr303-45.patch
>
>
> This one has its problems because it clashes directly with the
> MethodValidation implementation. I provide a candidate patch that follows the
> spec and doesn't break our extra functionality, please review it.
> Supplied patch:
> - Forces correct behavior of bean validation according to the spec: that is,
> a ValidationException is thrown. So, if you want to validate a bean which
> also has an annotated method, the implementation will follow the spec and
> throw an exception.
> - Method validation works, but it is slower than before as constraint
> descriptions are no longer cached. This can be fixed, I just left this for
> later as I prefer to concentrate in TCK tests and I also would like to gather
> opinions as if this is the correct route or you have a better idea for this.
> - 1 more TCK test passes.
> So, to sum it up, if this patch is merged, don't mix annotated fields/getters
> with annotated methods in the same class. On the bright side, constructor
> annotations can be mixed.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.