[hibernate-issues] [JIRA] (HV-1794) Optional containing a list of items is not being validated

Ihor Mochurad (JIRA) jira at hibernate.atlassian.net
Wed Jul 22 18:46:26 EDT 2020


Ihor Mochurad ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ccb2fc050ff750e51016e32 ) *created* an issue

Hibernate Validator ( https://hibernate.atlassian.net/browse/HV?atlOrigin=eyJpIjoiNmI3MTAxMzhmNTRhNDlhMWE1NjhhMzk2YWUxOTQyNDgiLCJwIjoiaiJ9 ) / Bug ( https://hibernate.atlassian.net/browse/HV-1794?atlOrigin=eyJpIjoiNmI3MTAxMzhmNTRhNDlhMWE1NjhhMzk2YWUxOTQyNDgiLCJwIjoiaiJ9 ) HV-1794 ( https://hibernate.atlassian.net/browse/HV-1794?atlOrigin=eyJpIjoiNmI3MTAxMzhmNTRhNDlhMWE1NjhhMzk2YWUxOTQyNDgiLCJwIjoiaiJ9 ) Optional containing a list of items is not being validated ( https://hibernate.atlassian.net/browse/HV-1794?atlOrigin=eyJpIjoiNmI3MTAxMzhmNTRhNDlhMWE1NjhhMzk2YWUxOTQyNDgiLCJwIjoiaiJ9 )

Issue Type: Bug Affects Versions: 6.0.18.Final Assignee: Unassigned Components: engine Created: 22/Jul/2020 15:46 PM Priority: Major Reporter: Ihor Mochurad ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ccb2fc050ff750e51016e32 )

As a user of Hibernate Validator, I would expect that a field like

`private Optional<List<ConsumerGroupDTO>> consumerGroups;`

where `ConsumerGroupDTO` is the following pojo:

@Data
@SuperBuilder
@NoArgsConstructor
public class ConsumerGroupDTO extends ConsumerDTO {

   private @NotEmpty String consumerGroupId;
   private boolean simpleConsumerGroup;

}

gets properly validated and constraint violation exception will be thrown in case `consumerGroupId` value will be set either to null or an empty string, instead validation does not kick-in for the list of pojos wrapped in the `Optional`.

If the value of `Optional` is a pojo or a primitive, validation rules are working fine.

I did a little bit more digging and tried to write my own value extractor:

public class OptionalListValueExtractor<T> implements ValueExtractor<@ExtractedValue(type = List.class) Optional<List<T>>> {
   @Override
   public void extractValues(@ExtractedValue(type = List.class) Optional<List<T>> originalValue, ValueReceiver valueReceiver) {
       valueReceiver.value( null , originalValue.orElse( null ));
   }
}

but when I register this class as a service, I get an exception with the cause:

Caused by: javax.validation.valueextraction.ValueExtractorDefinitionException: HV000225: Only unbound wildcard type arguments are supported for the container type of the value extractor: com.solace.maas.event.core.validation.OptionalListValueExtractor.

It seems it doesn't like that I have a class type specified in my Optional. But without this generic, it is impossible to have the extractor working the right way.

Anyways, I think it is either a bug in HV or a functional efficiency.

Looking forward to your reply!

( https://hibernate.atlassian.net/browse/HV-1794#add-comment?atlOrigin=eyJpIjoiNmI3MTAxMzhmNTRhNDlhMWE1NjhhMzk2YWUxOTQyNDgiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HV-1794#add-comment?atlOrigin=eyJpIjoiNmI3MTAxMzhmNTRhNDlhMWE1NjhhMzk2YWUxOTQyNDgiLCJwIjoiaiJ9 )

Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100133- sha1:ead1094 )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200722/be521a2f/attachment.html 


More information about the hibernate-issues mailing list