Details

    • Type: Bug Bug
    • Status: In Progress
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 0.4
    • Fix Version/s: None
    • Component/s: jsr303
    • Labels:
      None
    • Environment:

      JDK 1.6, Windows, Eclipse 3.7

      Description

      In the Test i have attached i have a @Size-Constraint on a method for validation of the returnvalue. In version 0.3 of bval-jsr303 it worked.
      In version 0.4 there is a change in the code:

      The method org.apache.bval.jsr303.extensions.patchFactoryContextForMethodValidation is no longer activ. Therefore all Jsr303MetaBeanFactory were no longer changed to MethodValidatorMetaBeanFactory.

      This has the affect that the method hasValidationConstraintsDefined() is used from Jsr303MetaBeanFactory which checks if there is a Constraint on the Method. If it is, a exception is thrown "Property %myMethod% does not follow javabean conventions".

      Mayby i use the annotions for validating returnvalues in a wrong way.

      I have attached an example.

      Thank you for your help.

      1. bval.zip
        3 kB
        Romain Manni-Bucau
      2. ValidationTest.jar
        32 kB
        Sascha Vujevic

        Activity

        Hide
        Romain Manni-Bucau added a comment -

        oki, thanks Matt!

        Show
        Romain Manni-Bucau added a comment - oki, thanks Matt!
        Hide
        Matt Benson added a comment -

        Hi, guys. This was a documentation oversight on my part. It was determined that, method validation being an optional feature, it was reasonable that the user be required to explicitly enable it, so in v0.4, you need to set the property apache.bval.metabean-factory-classnames to org.apache.bval.jsr303.extensions.MethodValidatorMetaBeanFactory. The way this was done on-the-fly at runtime was a little ugly in the code IMO. It may be possible to reenable the functionality for future versions; in any event method validation will be available by default when Apache BVal implements the forthcoming Bean Validation 1.1 specification. I'll leave this issue open until we determine whether and how we can reenable.

        Show
        Matt Benson added a comment - Hi, guys. This was a documentation oversight on my part. It was determined that, method validation being an optional feature, it was reasonable that the user be required to explicitly enable it, so in v0.4, you need to set the property apache.bval.metabean-factory-classnames to org.apache.bval.jsr303.extensions.MethodValidatorMetaBeanFactory . The way this was done on-the-fly at runtime was a little ugly in the code IMO. It may be possible to reenable the functionality for future versions; in any event method validation will be available by default when Apache BVal implements the forthcoming Bean Validation 1.1 specification. I'll leave this issue open until we determine whether and how we can reenable.
        Matt Benson made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Matt Benson made changes -
        Assignee Matt Benson [ mbenson ]
        Romain Manni-Bucau made changes -
        Attachment bval.zip [ 12533282 ]
        Hide
        Romain Manni-Bucau added a comment -

        Attached a maven project with a unit test reproducing the issue

        here the exception:

        javax.validation.ValidationException: error retrieving constraints for class org.apache.bval.issue.ReturnValueTest$Validatable
        at org.apache.bval.jsr303.ClassValidator.getConstraintsForClass(ClassValidator.java:266)
        at org.apache.bval.jsr303.extensions.MethodValidatorImpl.validateReturnedValue(MethodValidatorImpl.java:147)
        at org.apache.bval.issue.ReturnValueTest.failling(ReturnValueTest.java:14)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
        at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:76)
        at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
        at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
        Caused by: javax.validation.ValidationException: Property foo does not follow javabean conventions.
        at org.apache.bval.jsr303.Jsr303MetaBeanFactory.processClass(Jsr303MetaBeanFactory.java:162)
        at org.apache.bval.jsr303.Jsr303MetaBeanFactory.buildMetaBean(Jsr303MetaBeanFactory.java:95)
        at org.apache.bval.MetaBeanBuilder.buildForClass(MetaBeanBuilder.java:131)
        at org.apache.bval.MetaBeanManager.findForClass(MetaBeanManager.java:102)
        at org.apache.bval.jsr303.ClassValidator.getConstraintsForClass(ClassValidator.java:258)
        ... 28 more

        Show
        Romain Manni-Bucau added a comment - Attached a maven project with a unit test reproducing the issue here the exception: javax.validation.ValidationException: error retrieving constraints for class org.apache.bval.issue.ReturnValueTest$Validatable at org.apache.bval.jsr303.ClassValidator.getConstraintsForClass(ClassValidator.java:266) at org.apache.bval.jsr303.extensions.MethodValidatorImpl.validateReturnedValue(MethodValidatorImpl.java:147) at org.apache.bval.issue.ReturnValueTest.failling(ReturnValueTest.java:14) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.junit.runner.JUnitCore.run(JUnitCore.java:157) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:76) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) Caused by: javax.validation.ValidationException: Property foo does not follow javabean conventions. at org.apache.bval.jsr303.Jsr303MetaBeanFactory.processClass(Jsr303MetaBeanFactory.java:162) at org.apache.bval.jsr303.Jsr303MetaBeanFactory.buildMetaBean(Jsr303MetaBeanFactory.java:95) at org.apache.bval.MetaBeanBuilder.buildForClass(MetaBeanBuilder.java:131) at org.apache.bval.MetaBeanManager.findForClass(MetaBeanManager.java:102) at org.apache.bval.jsr303.ClassValidator.getConstraintsForClass(ClassValidator.java:258) ... 28 more
        Hide
        Sascha Vujevic added a comment -

        Could you please tell me details of the openejb-exception on the console, so i can see what is missing in the test. This one you have written is a generic one.

        Thank you for your help.

        Show
        Sascha Vujevic added a comment - Could you please tell me details of the openejb-exception on the console, so i can see what is missing in the test. This one you have written is a generic one. Thank you for your help.
        Hide
        Romain Manni-Bucau added a comment -

        Yep, this test doesnt valid the returned value. Return a string which should be @notnull

        Show
        Romain Manni-Bucau added a comment - Yep, this test doesnt valid the returned value. Return a string which should be @notnull
        Hide
        Matt Benson added a comment - - edited

        Any chance of something that runs and fails in the correct place? How does what you've just described, Romain, differ from the tests in http://svn.apache.org/viewvc/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/extensions/MethodValidatorImplTest.java?view=markup, for example?

        Thanks!

        Show
        Matt Benson added a comment - - edited Any chance of something that runs and fails in the correct place? How does what you've just described, Romain, differ from the tests in http://svn.apache.org/viewvc/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/extensions/MethodValidatorImplTest.java?view=markup , for example? Thanks!
        Hide
        Romain Manni-Bucau added a comment -

        Using an hello world returning a value @notnull and validated manually should fail too

        Show
        Romain Manni-Bucau added a comment - Using an hello world returning a value @notnull and validated manually should fail too
        Hide
        Matt Benson added a comment -

        Actually I don't think this example contains everything I need to run the test successfully. What I'm getting is:

        javax.naming.NamingException: Unable to find injection meta-data for de.ergodirekt.test.constraintTest.ConstraintValidationTest. Ensure that class was annotated with @org.apache.openejb.api.LocalClient and was successfully discovered and deployed. See http://openejb.apache.org/3.0/local-client-injection.html
        at org.apache.openejb.client.LocalInitialContext.inject(LocalInitialContext.java:198)
        at org.apache.openejb.client.LocalInitialContext.bind(LocalInitialContext.java:172)
        at javax.naming.InitialContext.bind(InitialContext.java:400)
        at de.ergodirekt.test.constraintTest.AbstractOpenEjbTest.setUpOpenEjb(AbstractOpenEjbTest.java:146)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
        at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

        Show
        Matt Benson added a comment - Actually I don't think this example contains everything I need to run the test successfully. What I'm getting is: javax.naming.NamingException: Unable to find injection meta-data for de.ergodirekt.test.constraintTest.ConstraintValidationTest. Ensure that class was annotated with @org.apache.openejb.api.LocalClient and was successfully discovered and deployed. See http://openejb.apache.org/3.0/local-client-injection.html at org.apache.openejb.client.LocalInitialContext.inject(LocalInitialContext.java:198) at org.apache.openejb.client.LocalInitialContext.bind(LocalInitialContext.java:172) at javax.naming.InitialContext.bind(InitialContext.java:400) at de.ergodirekt.test.constraintTest.AbstractOpenEjbTest.setUpOpenEjb(AbstractOpenEjbTest.java:146) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
        Hide
        Matt Benson added a comment -

        Hello! Having reconstructed a Maven project from the contents of the attached jar, it appears that ConstraintValidationTest#testReturnValueToLong() fails even if I change the bval-jsr303 dependency version to 0.3-incubating. Therefore I cannot reproduce that there is a true regression at work. I will continue to review the situation regarding whether the example should work independently of the question of there being a regression from v0.3-incubating to v0.4.

        Matt

        Show
        Matt Benson added a comment - Hello! Having reconstructed a Maven project from the contents of the attached jar, it appears that ConstraintValidationTest#testReturnValueToLong() fails even if I change the bval-jsr303 dependency version to 0.3-incubating. Therefore I cannot reproduce that there is a true regression at work. I will continue to review the situation regarding whether the example should work independently of the question of there being a regression from v0.3-incubating to v0.4. Matt
        Hide
        Romain Manni-Bucau added a comment -

        +1

        Show
        Romain Manni-Bucau added a comment - +1
        Sascha Vujevic made changes -
        Description In the Test i have attached in this bug, i have a @Size-Constraint on a method. In version 0.3 of bval-jsr303 it worked.
        In version 0.4 there were a change in the code:

        The method org.apache.bval.jsr303.extensions.patchFactoryContextForMethodValidation is no longer activ. Therefore all Jsr303MetaBeanFactory were no longer changed to MethodValidatorMetaBeanFactory.

        This has the affect that the method hasValidationConstraintsDefined() is used from Jsr303MetaBeanFactory which checks if there is a Constraint on the Method. If it is, a exception is thrown "Property %myMethod% does not follow javabean conventions".

        Mayby i use the annotions for validating returnvalues in a wrong way.

        I have attached an example.

        Thank you for your help.
        In the Test i have attached i have a @Size-Constraint on a method for validation of the returnvalue. In version 0.3 of bval-jsr303 it worked.
        In version 0.4 there is a change in the code:

        The method org.apache.bval.jsr303.extensions.patchFactoryContextForMethodValidation is no longer activ. Therefore all Jsr303MetaBeanFactory were no longer changed to MethodValidatorMetaBeanFactory.

        This has the affect that the method hasValidationConstraintsDefined() is used from Jsr303MetaBeanFactory which checks if there is a Constraint on the Method. If it is, a exception is thrown "Property %myMethod% does not follow javabean conventions".

        Mayby i use the annotions for validating returnvalues in a wrong way.

        I have attached an example.

        Thank you for your help.
        Sascha Vujevic made changes -
        Field Original Value New Value
        Attachment ValidationTest.jar [ 12533037 ]
        Sascha Vujevic created issue -

          People

          • Assignee:
            Matt Benson
            Reporter:
            Sascha Vujevic
          • Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:

              Development