Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-1203

Custom ConstraintValidator for existing Constraint causes {{javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type...}}

XMLWordPrintable

    • Hide

      Deploy my sample attached application and make following HTTP requests:

      Valid HTTP GET request:

      localhost:8080/test-war/api/admins/?page=1&pageSize=1

      causes unwanted internal exception javax.validation.UnexpectedTypeException:

        400 BAD REQUEST
        {
          "success": false,
          "errors": [
            "HV000030: No validator could be found for type: resteasy.bug.showcase.params.IntParam."
          ]
        }
      

      While invalid HTTP GET request:

      localhost:8080/test-war/api/admins/?page=-2&pageSize=-2

      causes proper validation and desired output:

        422 Unprocessable Entity
        {
          "success": false,
          "errors": [
            "page must be greater than or equal to 1",
            "pageSize must be greater than or equal to 1"
          ]
        }
      
      Show
      Deploy my sample attached application and make following HTTP requests: Valid HTTP GET request: localhost:8080/test-war/api/admins/?page=1&pageSize=1 causes unwanted internal exception javax.validation.UnexpectedTypeException : 400 BAD REQUEST { "success" : false , "errors" : [ "HV000030: No validator could be found for type: resteasy.bug.showcase.params.IntParam." ] } While invalid HTTP GET request: localhost:8080/test-war/api/admins/?page=-2&pageSize=-2 causes proper validation and desired output: 422 Unprocessable Entity { "success" : false , "errors" : [ "page must be greater than or equal to 1" , "pageSize must be greater than or equal to 1" ] }
    • Workaround Exists
    • Hide

      Switching to xml approach: META-INF/validation.xml and removing validation configuration (mainly custom constraint mapping) from my custom @Provider class (I mean resteasy.bug.showcase.ValidationConfigurationContextResolver) causes the bug to disappear. Validation is then performed correctly.

      Show
      Switching to xml approach: META-INF/validation.xml and removing validation configuration (mainly custom constraint mapping) from my custom @Provider class (I mean resteasy.bug.showcase.ValidationConfigurationContextResolver ) causes the bug to disappear. Validation is then performed correctly.
    • Low

      See attached sample small project test.zip.

      Bug is about using built-in @javax.validation.constraints.Min constraint annotation for validating my custom type: resteasy.bug.showcase.params.IntParam but only when configuring validation within @Provider class. Hibernate-validator cannot find my validator when request is valid - but in the same time can find it when a request is invalid.

      javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: resteasy.bug.showcase.params.IntParam
      at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.verifyResolveWasUnique(ConstraintValidatorManager.java:218)
      at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.findMatchingValidatorClass(ConstraintValidatorManager.java:193)
      at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.getInitializedValidator(ConstraintValidatorManager.java:97)
      at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:125)
      at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:91)
      at org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:83)
      at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:547)
      at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:487)
      at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:451)
      at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:403)
      at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:206)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.jboss.weld.bean.proxy.AbstractBeanInstance.invoke(AbstractBeanInstance.java:38)
      at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:100)
      at org.jboss.weld.proxies.Validator$976505265$Proxy$_$$_WeldClientProxy.validate(Unknown Source)
      at resteasy.bug.showcase.resources.AdminEndpoint.getAdmins(AdminEndpoint.java:28)
      

            rsigal@redhat.com Ronald Sigal
            gdemecki Grzegorz Demecki (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: