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 warnings are displayed when optional ResourceBundles are missing #21694

Closed
gastaldi opened this issue Nov 25, 2021 · 11 comments · Fixed by #22475
Closed

Hibernate Validator warnings are displayed when optional ResourceBundles are missing #21694

gastaldi opened this issue Nov 25, 2021 · 11 comments · Fixed by #22475
Assignees
Labels
area/hibernate-validator Hibernate Validator kind/bug Something isn't working
Milestone

Comments

@gastaldi
Copy link
Contributor

Describe the bug

When an app depending on the Hibernate Validator extension is package using the native build, the following messages are printed to the output:

The bundle named: ContributorValidationMessages, has not been found. If the bundle is part of a module, verify the bundle name is a fully qualified class name. Otherwise verify the bundle path is accessible in the classpath.
The bundle named: ValidationMessages, has not been found. If the bundle is part of a module, verify the bundle name is a fully qualified class name. Otherwise verify the bundle path is accessible in the classpath.
The bundle named: messages, has not been found. If the bundle is part of a module, verify the bundle name is a fully qualified class name. Otherwise verify the bundle path is accessible in the classpath.

Although that does no harm to the build, it may lead to confusion giving that those bundles are optional.

Expected behavior

Do not print any message if the bundle does not exist in the user's application

Actual behavior

The message is printed.

How to Reproduce?

  1. Clone https://github.com/quarkusio/registry.quarkus.io
  2. run mvn clean package -Dnative -DskipTests

Output of uname -a or ver

Fedora 35

Output of java -version

11

GraalVM version (if different from Java)

21

Quarkus version or git rev

2.5.0.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Maven 3.8.4

Additional information

This issue was originated from a chat in Zulip.

Also it seems that this snippet may need to be enhanced to check if the bundle really exists

@gastaldi gastaldi added the kind/bug Something isn't working label Nov 25, 2021
@quarkus-bot

This comment has been minimized.

@quarkus-bot quarkus-bot bot added the area/hibernate-validator Hibernate Validator label Nov 25, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Nov 25, 2021

/cc @gsmet, @yrodiere

@bboyz269
Copy link

bboyz269 commented Jan 10, 2022

Hi, I still see complain about "message" bundle not found in 2.6.1.Final. Is this intended?

The bundle named: messages, has not been found. If the bundle is part of a module, verify the bundle name is a fully qualified class name. Otherwise verify the bundle path is accessible in the classpath.

// I'm on gradle 7.1, kotlin 1.6.10, java 11, container build in windows
Reproducible repo: https://github.com/bboyz269/quarkus-resource-bundle-warning

@gsmet
Copy link
Member

gsmet commented Jan 10, 2022

Your problem is due to the fact that there is a messages resource bundle in the Kotlin compiler jar:

jar:file:/home/gsmet/.m2/repository/org/jetbrains/kotlin/kotlin-compiler/1.6.10/kotlin-compiler-1.6.10.jar!/messages

and when we are testing if a messages is around before adding it to the native resource bundles, this resource is accessible but it is not accessible at runtime anymore.

@aloubyansky @stuartwdouglas while not critical, this is yet another occurrence of the CL used to test if classes/resources are available at build time being polluted with the build artifacts. What we usually want to do is to test if the thing will be available at runtime (I remember I posted something somewhere about the Infinispan test server polluting the classpath big time).

@aloubyansky
Copy link
Member

With #22673 merged, the following will fix it

diff --git a/extensions/hibernate-validator/deployment/src/main/java/io/quarkus/hibernate/validator/deployment/HibernateValidatorProcessor.java b/extensions/hibernate-validator/deployment/src/main/java/io/quarkus/hibernate/validator/deployment/HibernateValidatorProcessor.java
index 4e815d3da6..8132a1de2a 100644
--- a/extensions/hibernate-validator/deployment/src/main/java/io/quarkus/hibernate/validator/deployment/HibernateValidatorProcessor.java
+++ b/extensions/hibernate-validator/deployment/src/main/java/io/quarkus/hibernate/validator/deployment/HibernateValidatorProcessor.java
@@ -54,6 +54,8 @@ import io.quarkus.arc.deployment.UnremovableBeanBuildItem;
 import io.quarkus.arc.processor.BeanInfo;
 import io.quarkus.arc.processor.BuiltinScope;
 import io.quarkus.arc.processor.DotNames;
+import io.quarkus.bootstrap.classloading.ClassPathElement;
+import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
 import io.quarkus.deployment.Capabilities;
 import io.quarkus.deployment.Capability;
 import io.quarkus.deployment.Feature;
@@ -353,8 +355,11 @@ class HibernateValidatorProcessor {
         List<String> userDefinedHibernateValidatorResourceBundles = new ArrayList<>();
 
         for (String potentialHibernateValidatorResourceBundle : potentialHibernateValidatorResourceBundles) {
-            if (Thread.currentThread().getContextClassLoader().getResource(potentialHibernateValidatorResourceBundle) != null) {
-                userDefinedHibernateValidatorResourceBundles.add(potentialHibernateValidatorResourceBundle);
+            for (ClassPathElement cpe : QuarkusClassLoader.getElements(potentialHibernateValidatorResourceBundle, false)) {
+                if (cpe.isRuntime()) {
+                    userDefinedHibernateValidatorResourceBundles.add(potentialHibernateValidatorResourceBundle);
+                    break;
+                }
             }
         }
 
diff --git a/extensions/resteasy-classic/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java b/extensions/resteasy-classic/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java
index f8cd5e3cc6..3b05553e7c 100755
--- a/extensions/resteasy-classic/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java
+++ b/extensions/resteasy-classic/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java
@@ -56,6 +56,8 @@ import io.quarkus.arc.processor.AnnotationsTransformer;
 import io.quarkus.arc.processor.BuiltinScope;
 import io.quarkus.arc.processor.DotNames;
 import io.quarkus.arc.processor.Transformation;
+import io.quarkus.bootstrap.classloading.ClassPathElement;
+import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
 import io.quarkus.deployment.annotations.BuildProducer;
 import io.quarkus.deployment.annotations.BuildStep;
 import io.quarkus.deployment.builditem.BytecodeTransformerBuildItem;
@@ -182,13 +184,14 @@ public class ResteasyServerCommonProcessor {
 
     @BuildStep
     NativeImageConfigBuildItem config() {
-        if (Thread.currentThread().getContextClassLoader().getResource(MESSAGES_RESOURCE_BUNDLE) == null) {
-            return null;
+        for (ClassPathElement cpe : QuarkusClassLoader.getElements(MESSAGES_RESOURCE_BUNDLE, false)) {
+            if (cpe.isRuntime()) {
+                return NativeImageConfigBuildItem.builder()
+                        .addResourceBundle(MESSAGES_RESOURCE_BUNDLE)
+                        .build();
+            }
         }
-
-        return NativeImageConfigBuildItem.builder()
-                .addResourceBundle(MESSAGES_RESOURCE_BUNDLE)
-                .build();
+        return null;
     }

@gsmet
Copy link
Member

gsmet commented Jan 10, 2022

@aloubyansky oh, that's very cool! I'll have a look at this once #22673 is in then. And I wonder if we should have a look at other occurrences, typically when we test if a class is present in the processors (we do that in several places).

@aloubyansky
Copy link
Member

Yes, and I guess we could have a more convenient API for these kind of classpath resource look-ups.

@gsmet
Copy link
Member

gsmet commented Jan 10, 2022

That was my next question :).

@aloubyansky
Copy link
Member

@gsmet are you taking care of the issue or want me to do anything about it?

@gsmet
Copy link
Member

gsmet commented Jan 12, 2022

I will implement what you described above but I will let you come up with the nicer API given I have very little knowledge of this area :).

Once we have the API, I think I'll go through the processors to try to fix the issues we have with class detection.

gsmet added a commit to gsmet/quarkus that referenced this issue Jan 17, 2022
Instead of checking the CL, we check only the runtime elements so we are
sure the elements will be available at runtime.

Related to quarkusio#21694
@gsmet
Copy link
Member

gsmet commented Jan 17, 2022

#22938 will fix it once and for all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-validator Hibernate Validator kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants