-
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
Fix unregistered element accesses when using Hibernate ORM in native mode #45654
Fix unregistered element accesses when using Hibernate ORM in native mode #45654
Conversation
/cc @gsmet (hibernate-orm) |
This comment has been minimized.
This comment has been minimized.
4ee8cc6
to
d34bed5
Compare
This comment has been minimized.
This comment has been minimized.
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.
Looks fine to me but let's make sure @yrodiere has a look at it before merging.
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.
Thanks.
Some of the changes definitely make sense, but others are suspicious... it seems you end up having to register services that should only be retrieved during static init. I wonder if it's a case of misdetection? Or maybe these services are retrieved at runtime, even though they shouldn't be?
...s/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/ClassNames.java
Outdated
Show resolved
Hide resolved
...s/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/ClassNames.java
Show resolved
Hide resolved
...s/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/ClassNames.java
Outdated
Show resolved
Hide resolved
// Accessed in org.hibernate.boot.beanvalidation.BeanValidationIntegrator.loadTypeSafeActivatorClass | ||
reflectiveClasses.produce(ReflectiveClassBuildItem.builder("org.hibernate.boot.beanvalidation.TypeSafeActivator") | ||
.methods().fields().build()); | ||
// Accessed in org.hibernate.boot.beanvalidation.BeanValidationIntegrator.isBeanValidationApiAvailable | ||
reflectiveClasses.produce(ReflectiveClassBuildItem.builder(BeanValidationIntegrator.JAKARTA_BV_CHECK_CLASS) | ||
.constructors(false).build()); |
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.
Alternatively, we could skip this code when the HIBERNATE_VALIDATOR
capability is not present:
Line 479 in b4b93ad
integrators.add(new BeanValidationIntegrator()); |
And then we'd be able to keep the if
in this method, because BeanValidationIntegrator.isBeanValidationApiAvailable
wouldn't be called when the if
condition is false
.
Though maybe that "optimization" is not worth it, I don't know.
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.
Seems reasonable, but I don't know how to check if the validator capability is present.
...s/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/ClassNames.java
Show resolved
Hide resolved
...s/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/ClassNames.java
Show resolved
Hide resolved
...s/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/ClassNames.java
Show resolved
Hide resolved
...s/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/ClassNames.java
Outdated
Show resolved
Hide resolved
d34bed5
to
4162a28
Compare
Thanks for the review @yrodiere. Comments addressed. |
This comment has been minimized.
This comment has been minimized.
The class is accessed even when not using hibernate validator. Relates to quarkusio#41995
Accessed by `com.github.benmanes.caffeine.cache.LocalCacheFactory.newFactory` Relates to quarkusio#41995
4162a28
to
ebab4ce
Compare
I force-pushed a fix to the unordered imports in the first commit. Rebased on main while I was at it. I'll try to add a commit to address the Hibernate Validator capability check. |
This comment has been minimized.
This comment has been minimized.
@yrodiere It looks like we need the following patch as well: diff --git a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java
index f40a528c1d4..a6d0dce484f 100644
--- a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java
+++ b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java
@@ -240,10 +240,13 @@ AdditionalIndexedClassesBuildItem addPersistenceUnitAnnotationToIndex() {
@BuildStep
public void enrollBeanValidationTypeSafeActivatorForReflection(Capabilities capabilities,
- BuildProducer<ReflectiveClassBuildItem> reflectiveClasses) {
+ BuildProducer<ReflectiveClassBuildItem> reflectiveClasses, BuildProducer<ServiceProviderBuildItem> services) {
// Accessed in org.hibernate.boot.beanvalidation.BeanValidationIntegrator.loadTypeSafeActivatorClass
reflectiveClasses.produce(ReflectiveClassBuildItem.builder("org.hibernate.boot.beanvalidation.TypeSafeActivator")
.methods().fields().build());
+ // Accessed in jakarta.validation.Validation$GetValidationProviderListAction.loadProviders through
+ // org.hibernate.boot.beanvalidation.BeanValidationIntegrator.integrate
+ services.produce(ServiceProviderBuildItem.allProvidersFromClassPath("jakarta.validation.spi.ValidationProvider"));
// Accessed in org.hibernate.boot.beanvalidation.BeanValidationIntegrator.isBeanValidationApiAvailable
reflectiveClasses.produce(ReflectiveClassBuildItem.builder(BeanValidationIntegrator.JAKARTA_BV_CHECK_CLASS)
.constructors(false).build()); |
This looks like something that the Hibernate Validator extension itself should add, or bypass... do you have a precise stack trace? |
Actually we set the validator factory explicitly here in Hibernate ORM: Lines 187 to 189 in 47ecd0a
So I wouldn't expect us to rely on the Bean Validation bootstrap. I suspect the problem you noticed is a result of adding the Hopefully the commit I just pushed (which only adds the |
This comment has been minimized.
This comment has been minimized.
Alright, I've been too optimistic with my push. Will debug locally... |
…ction in Hibernate ORM extension
6cc26fd
to
fd4e51a
Compare
Done and pushed a fix. It was just a misnamed contructor parameter confusing the bytecode recording stuff... |
Thank you @yrodiere
I confirm it does. |
Status for workflow
|
Registers:
jakarta.validation.ConstraintViolation
unconditionallycom.github.benmanes.caffeine.cache.NodeFactory#FACTORY
for reflectionRelates to #41995