Hibernate Validator: @ApplicationScoped
custom ValueExtractor
bean lead to ValueExtractorDefinitionException
#20375
Labels
Milestone
Describe the bug
Even after we fix #20347, custom
ValueExtractor
implementations provided as CDI beans can only have the@Singleton
scope or@Dependent
pseudo-scope. Any scope requiring instantiation will lead to an exception on startup complaining about "parallel definitions of value extractors on a given class", even though that's not the case.Expected behavior
A value extractor annotated with
@ApplicationScoped
should be correctly added to theValidatorFactory
, and be used automatically to constraints on extracted elements (e.g.Container<@NotBlank String>
).Actual behavior
Exception on startup:
How to Reproduce?
I'm going to add a disabled test as part of the PR for #20347. Look for
ApplicationScopedCustomValueExtractorTest
in the codebase.Output of
uname -a
orver
No response
Output of
java -version
No response
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.3.0.CR1, f0aba85
Build tool (ie. output of
mvnw --version
orgradlew --version
)No response
Additional information
I believe the cause is a bug in
org.hibernate.validator.internal.engine.valueextraction.ValueExtractorDescriptor#determineValueExtractorDefinitions
. It gets passed the proxy class, which extends the actual implementation class. And for some reason, when passed a class that extends another class that implementsValueExtractor
, it behaves as ifValueExtractor
was implemented multiple times, both by the superclass and the subclass.It seems caused by the fact that
java.lang.Class#getAnnotatedInterfaces
returns annotated interfaces of the class and its superclasses, which meansdetermineValueExtractorDefinitions
should not be walking through superclasses to collect all annotated interfaces (when it does, it collects duplicates).The text was updated successfully, but these errors were encountered: