Validator.validateValue() prints no violations on an interface

Description

The Validator.validateValue() seems to be ignoring validation annotations on an interface. Example:

Not sure whether it’s by design (interface is technically not a bean), or accidental.

Use-case: I’m using ktorm for persistency; ktorm entities are interfaces with backing proxy (strange but that’s how ktorm rolls). I’m trying to write an UI in Vaadin performing validation of ktorm entities, but the validators do not fire.

Why I think this might be a bug: feels like there’s an inconsistency here, in a way that MyBean2 seems to be inheriting validation annotations from the interface. In my opinion, cases 2+3+4 should return consistent outputs: either all should return no violations, or they should return one violation.

Of course, from my point of view, it would be best if one violation is returned

If it’s decided to fix this, it would be great to backport to javax.validation as well please.

Environment

openjdk 21

Activity

Show:

Marko Bekhta July 31, 2024 at 8:47 AM

Hey

Thanks for bringing this up. I’ve looked at the spec and could find anything explicitly mentioning what should be the behaviour for calling the validateValue and passing an interface… Hence it is up to the implementation to decide.

Returning an empty set of violations is definitely misleading in this case. It should either clearly throw an exception as rejecting working with an interface or perform the validation. Let me see if we could make a clean change to support such a use case.

Fixed

Details

Assignee

Reporter

Bug Testcase Reminder (view)

Bug reports should generally be accompanied by a test case!

Bug Testcase Reminder (edit)

Bug reports should generally be accompanied by a test case!

backPortable

Backport?

Participants

Marko Bekhta
Martin Vysny

Components

Fix versions

Affects versions

Priority

Created July 31, 2024 at 7:05 AM
Updated September 4, 2024 at 4:24 PM
Resolved September 3, 2024 at 1:56 PM