[hibernate-issues] [Hibernate-JIRA] Commented: (HV-573) Need graceful handling of return value constraint applied to method with void return type

Gunnar Morling (JIRA) noreply at atlassian.com
Fri Apr 13 09:35:49 EDT 2012


    [ https://hibernate.onjira.com/browse/HV-573?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=46279#comment-46279 ] 

Gunnar Morling commented on HV-573:
-----------------------------------

While working on the issue I came to the conclusion that the actual error is that we're trying to unbox the type {{java.lang.Void}}.

We could easily avoid this and then rely on the standard validator resolution which simply won't find a validator for that type. The error message then would be 

{code}
javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: void.
{code}

Alternatively we could throw a {{ConstraintDeclarationException}} as discussed, clearly saying that void methods may not be annotated with a return value constraint.

I think I'd prefer the first approach, it's IMO more regular and even would allow for the use case that someone purposefully implements a {{ConstraintValidator<SomeAnnotation, Void>}}, e.g. to implement a generic post condition check based on the current environment state.

WDYT?

> Need graceful handling of return value constraint applied to method with void return type
> -----------------------------------------------------------------------------------------
>
>                 Key: HV-573
>                 URL: https://hibernate.onjira.com/browse/HV-573
>             Project: Hibernate Validator
>          Issue Type: Bug
>          Components: engine
>            Reporter: Ron Sigal
>            Assignee: Gunnar Morling
>            Priority: Minor
>             Fix For: 4.3.0.CR1
>
>
> In Resteasy, I inadvertently created a method
> {code}
> @FooConstraint(min=3,max=5)
> public void postImposed(Foo foo){
> }
> {code}
> and got
> {noformat}
> java.lang.RuntimeException: Unhandled primitive type.
> 	at org.hibernate.validator.util.ReflectionHelper.boxedType(ReflectionHelper.java:722)
> 	at org.hibernate.validator.metadata.location.MethodConstraintLocation.typeOfAnnotatedElement(MethodConstraintLocation.java:74)
> 	at org.hibernate.validator.metadata.MetaConstraint.typeOfAnnotatedElement(MetaConstraint.java:92)
> 	at org.hibernate.validator.metadata.MetaConstraint.validateConstraint(MetaConstraint.java:82)
> 	at org.hibernate.validator.engine.ValidatorImpl.validateReturnValueForGroup(ValidatorImpl.java:1120)
> 	at org.hibernate.validator.engine.ValidatorImpl.validateReturnValueForGroup(ValidatorImpl.java:1082)
> 	at org.hibernate.validator.engine.ValidatorImpl.validateReturnValueInContext(ValidatorImpl.java:1022)
> 	at org.hibernate.validator.engine.ValidatorImpl.validateReturnValue(ValidatorImpl.java:245)
> 	at org.jboss.resteasy.plugins.providers.validation.GeneralValidatorImpl.validateReturnValue(GeneralValidatorImpl.java:71)
>         ...
> {noformat}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list