bval-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matt Benson (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (BVAL-169) Multiple method return values marked @Valid in hierarchy
Date Tue, 26 Feb 2019 23:32:00 GMT

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

Matt Benson commented on BVAL-169:
----------------------------------

The only reason I can think of is that if the {{@Valid}} annotation were accompanied by {{@ConvertGroups}}
then it might be possible to get into an ambiguous situation WRT the group conversions. The
spec does leave room for implementation-specific modes to relax certain of these types of
restrictions. You are welcome to convert this issue to a request for a custom configuration
property to enable this behavior. You are even more welcome to submit a patch implementing
this feature.

Matt

> Multiple method return values marked @Valid in hierarchy
> --------------------------------------------------------
>
>                 Key: BVAL-169
>                 URL: https://issues.apache.org/jira/browse/BVAL-169
>             Project: BVal
>          Issue Type: Bug
>    Affects Versions: 2.0.0
>            Reporter: Piotr Findeisen
>            Priority: Major
>
> In Validation 2.0 API, {{@Valid}} annotation is applicable to TYPE_USE.
> As a result, tools tend to copy the annotation (as any other type annotation), when generating
overriding methods. Examples:
> - overriding method in IntelliJ (tested in 2018.2.6)
> - generating implementation using {{@AutoValue}} (https://github.com/google/auto)
> When {{@Valid}} is found both on base method and an overriding method, BVal refuses to
work:
> {noformat}
> javax.validation.ConstraintDeclarationException: Multiple method return values marked
@Valid in hierarchy [Meta.ForMethod(public java.lang.String TestValidation$Subclass.getSomeValue()),
Meta.ForMethod(public java.lang.String TestValidation$Invalid.getSomeValue())]
> 	at org.apache.bval.jsr.metadata.Liskov.noRedeclarationOfReturnValueCascading(Liskov.java:172)
> 	at org.apache.bval.jsr.metadata.Liskov.validateContainerHierarchy(Liskov.java:118)
> 	at org.apache.bval.jsr.metadata.HierarchyBuilder$ForContainer.<init>(HierarchyBuilder.java:302)
> 	at org.apache.bval.jsr.metadata.HierarchyBuilder.forContainer(HierarchyBuilder.java:372)
> 	at org.apache.bval.jsr.metadata.CompositeBuilder$ForExecutable.getReturnValue(CompositeBuilder.java:204)
> 	at org.apache.bval.jsr.descriptor.MetadataReader$ForExecutable.getReturnValueDescriptor(MetadataReader.java:367)
> 	at org.apache.bval.jsr.descriptor.ExecutableD.<init>(ExecutableD.java:43)
> 	at org.apache.bval.jsr.descriptor.MethodD.<init>(MethodD.java:32)
> 	at org.apache.bval.jsr.descriptor.MetadataReader$ForBean.lambda$getMethods$6(MetadataReader.java:190)
> 	at java.util.HashMap.forEach(HashMap.java:1289)
> 	at org.apache.bval.jsr.descriptor.MetadataReader$ForBean.getMethods(MetadataReader.java:186)
> 	at org.apache.bval.jsr.descriptor.BeanD.<init>(BeanD.java:56)
> 	at org.apache.bval.jsr.descriptor.DescriptorManager.getBeanDescriptor(DescriptorManager.java:81)
> 	at org.apache.bval.jsr.job.ValidationJob.getBeanDescriptor(ValidationJob.java:577)
> 	at org.apache.bval.jsr.job.ValidationJob.access$200(ValidationJob.java:81)
> 	at org.apache.bval.jsr.job.ValidationJob$BeanFrame.<init>(ValidationJob.java:246)
> 	at org.apache.bval.jsr.job.ValidationJob$BeanFrame.<init>(ValidationJob.java:242)
> 	at org.apache.bval.jsr.job.ValidateBean.computeBaseFrame(ValidateBean.java:40)
> 	at org.apache.bval.jsr.job.ValidationJob.getResults(ValidationJob.java:555)
> 	at org.apache.bval.jsr.ValidatorImpl.validate(ValidatorImpl.java:53)
> 	at TestValidation.validate(TestValidation.java:14)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> 	at java.lang.reflect.Method.invoke(Method.java:498)
> 	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
> 	at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
> 	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:821)
> 	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1131)
> 	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
> 	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
> 	at org.testng.TestRunner.privateRun(TestRunner.java:773)
> 	at org.testng.TestRunner.run(TestRunner.java:623)
> 	at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
> 	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
> 	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
> 	at org.testng.SuiteRunner.run(SuiteRunner.java:259)
> {noformat}
> Minimal code reproducing the problem
> {code:java}
> import org.apache.bval.jsr.ApacheValidationProvider;
> import org.testng.annotations.Test;
> import javax.validation.Valid;
> public class TestValidation
> {
>     @Test
>     public void validate()
>     {
>         javax.validation.Validation.byProvider(ApacheValidationProvider.class)
>                 .configure().buildValidatorFactory().getValidator()
>                 .validate(new Subclass());
>     }
>     public static class Invalid
>     {
>         @Valid
>         public String getSomeValue() { return "whatever"; }
>     }
>     public static class Subclass
>             extends Invalid
>     {
>         @Override
>         public @Valid /* the annotation here was automatically inserted by IntelliJ */
String getSomeValue() { return super.getSomeValue(); }
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message