[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:48:24 EDT 2020


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

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

Change By: Ihor Mochurad ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ccb2fc050ff750e51016e32 )

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

` {noformat} private Optional<List<ConsumerGroupDTO>> consumerGroups; ` {noformat}

where ` * ConsumerGroupDTO ` * is the following pojo:

{code:java}
@Data
@SuperBuilder
@NoArgsConstructor
public class ConsumerGroupDTO extends ConsumerDTO {

private @NotEmpty String consumerGroupId;
private boolean simpleConsumerGroup;

}
{code}

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:

{code:java}
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));
}
}
{code}

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

{code:java}
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.
{code}

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=eyJpIjoiMTFiMTIwOTVlMzNiNGZmMTk3ZjQxZTI3MDA5NTFjZjAiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HV-1794#add-comment?atlOrigin=eyJpIjoiMTFiMTIwOTVlMzNiNGZmMTk3ZjQxZTI3MDA5NTFjZjAiLCJwIjoiaiJ9 )

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/595550b8/attachment.html 


More information about the hibernate-issues mailing list