Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hibernate Validator: Correctly detect custom ValueExtractor beans #20382

Merged
merged 4 commits into from
Sep 27, 2021

Conversation

yrodiere
Copy link
Member

Fixes #20347 , though not completely: there are still limitations, reported as #20375 and #20377 .

So for now, custom ValueExtractor beans will only work properly if they are annotated with @Singleton, and perhaps @Dependent; they definitely won't work if annotated with @ApplicationScoped (because of #20375).

@quarkus-bot quarkus-bot bot added the area/hibernate-validator Hibernate Validator label Sep 24, 2021
Comment on lines +36 to +37
private static final TypeLiteral<ValueExtractor<?>> TYPE_LITERAL_VALUE_EXTRACTOR_WITH_WILDCARD = new TypeLiteral<ValueExtractor<?>>() {
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only way I found to select all beans implementing ValueExtractor<Something>.

Strangely, .select(ValueExtractor.class) does not match a bean implementing ValueExtractor<List<?>>, for example.

I say strangely, because you can definitely assign ValueExtractor<List<?>> to a variable of type ValueExtractor (the raw type). So if you consider that .select(ValueExtractor.class) should select all beans that can be assigned to ValueExtractor (the raw type), then beans implementing ValueExtractor<List<?>> should definitely be selected.

But no, that's not how it works, apparently.

According to the javadoc on io.quarkus.arc.impl.BeanTypeAssignabilityRules#matches(java.lang.Class<?>, java.lang.reflect.ParameterizedType):

     * A parameterized bean type is considered assignable to a raw required type if the raw types are identical and all type
     * parameters of the bean type are
     * either unbounded type variables or java.lang.Object.

So according to this definition, ValueExtractor<T> is assignable to ValueExtractor, but ValueExtractor<List<?>> is not.

@stuartwdouglas is this on purpose? Or should we adjust the implementation of io.quarkus.arc.impl.BeanTypeAssignabilityRules#matches(java.lang.Class<?>, java.lang.reflect.ParameterizedType)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a question for @mkouba, but this sounds like a bug.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sorry for the noise. Created #20410 for @mkouba :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works as required by the spec: "A parameterized bean type is considered assignable to a raw required type if the raw types are identical and all type parameters of the bean type are either unbounded type variables or java.lang.Object"; see also https://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#assignable_parameters

@gsmet gsmet merged commit c5b743c into quarkusio:main Sep 27, 2021
@quarkus-bot quarkus-bot bot added this to the 2.4 - main milestone Sep 27, 2021
@geoand geoand modified the milestones: 2.4 - main, 2.3.0.Final Sep 28, 2021
@yrodiere yrodiere deleted the i20347-valueextractor branch May 31, 2022 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-validator Hibernate Validator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hibernate-Validator: Custom ValueExtractor is not automatically registered
5 participants