-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Conversation
private static final TypeLiteral<ValueExtractor<?>> TYPE_LITERAL_VALUE_EXTRACTOR_WITH_WILDCARD = new TypeLiteral<ValueExtractor<?>>() { | ||
}; |
There was a problem hiding this comment.
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)
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
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).