Cross-parameter constraint is disallowed by Annotation Processor

Description

I am using hibernate validator 5.0.3 with Java 1.6.0_45-b06-451 on OSX 10.9.1.

I have created a cross-parameter constraint as follows:

CrossParameterConstraint.java

CrossParameterConstraintValidator.java

The above constraint is used in a method as follows:

CrossParameterConstraintUsageExample.java

I have configured the Annotation Processor in pom.xml
as follows:

pom.xml

When trying to compile, the Annotation Processor reports the following error:

The annotation @CrossParameterConstraint is disallowed for the return type of this method.

Environment

hibernate validator 5.0.3 with Java 1.6.0_45-b06-451 on OSX 10.9.1.

Activity

Show:
George Fountopoulos
February 11, 2014, 2:10 PM

Changing the type parameter from Object[] to Object in CrossParameterConstraintValidator seems to do the trick. However, the issue still applies for the case when Object[] type parameter is used. As mentioned in cross-parameter constraint documentation: The type parameter T from the ConstraintValidator interface must resolve to either Object or Object[] in order to receive the array of method/constructor arguments in the isValid() method.

Gunnar Morling
February 11, 2014, 3:04 PM

Hi Georgios, thanks for reporting this issue. The annotation processor does not yet support method/constructor constraints and thus cross-parameter constraints. Good to hear that you found a workaround for the time being.

That said, would you be interested in contributing a fix for this? The processor code base is quite straight-forward so it would be a great chance if you'd like to dive a bit into Hibernate Validator development If you're interested I could give you some guidance on the general design and how to get started.

George Fountopoulos
February 12, 2014, 12:40 PM

Thanks for the response Gunnar. I would very much like to contribute a fix, however, am working on new product development at the moment and on a pretty tight schedule. I will try and find some time to create the fix but cannot promise it will be any time soon. The good thing is that the issue is not a blocker and there is a workaround that I can use for now.

Nicola Tivarelli
January 3, 2016, 4:47 PM

I found out that cross-parameter constraints were not supported by hibernate annotation processor. In the example provided, the processor was trying to compare Object or Object[] to the return type of the method, not to the parameters.

I've implemented the support for cross-parameter constraints, added most of the checks and related test cases.

The code is attached to the following pull request: https://github.com/hibernate/hibernate-validator/pull/455

Fixed

Assignee

Unassigned

Reporter

George Fountopoulos

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Suitable for new contributors

Yes, likely

backportDecision

None

backportReEvaluate

None

Components

Fix versions

Affects versions

Priority

Major
Configure