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

Quarkus Classloader in Test not returning all results #40371

Closed
rdehuyss opened this issue Apr 30, 2024 · 2 comments · Fixed by #40384
Closed

Quarkus Classloader in Test not returning all results #40371

rdehuyss opened this issue Apr 30, 2024 · 2 comments · Fixed by #40384
Labels
area/core area/gradle Gradle kind/bug Something isn't working
Milestone

Comments

@rdehuyss
Copy link
Contributor

rdehuyss commented Apr 30, 2024

Describe the bug

Hi there, I'm Ronald and the creator of https://github.com/jobrunr/jobrunr.

I'm currently writing an extra test using @QuarkusTest and I'm loading resources from the classpath. My setup is Intellij / a multimodule Gradle project / Quarkus.

I'm using the following code:

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Enumeration<URL> contextClassLoaderResources = classLoader.getResources(folder);
List<URL> result = Collections.list(classLoaderResources)

Currently, I only have the following result:
file:/Users/rdehuyss/Projects/JobRunr/jobrunr/core/build/classes/java/main/org/jobrunr/storage/sql/common/migrations

However, I also expected the following result:
file:/Users/rdehuyss/Projects/JobRunr/jobrunr/core/build/resources/main/org/jobrunr/storage/sql/common/migrations

From what I understand, the JavaDoc of getResources mentions:

Finds all the resources with the given name.

If I do

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL url = classLoader.getResource(folder + "/v000__create_migrations_table.sql")

then the url is available and the resource is found.

Any idea why the classloader.getResources(folder) is not returning the actual resources but only the java classes? Is this a bug in the Quarkus ClassLoader?

Expected behavior

Return all the resources on the classpath.

Actual behavior

Only returns first resource on the classath

How to Reproduce?

See https://github.com/rdehuyss/quarkus-classloader-reproducer.

The ClassLoaderTest in the module quarkus should succeed whereas it currently fails.

Output of uname -a or ver

Darwin Ronalds-MacBook-Pro.local 23.3.0 Darwin Kernel Version 23.3.0: Wed Dec 20 21:31:10 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6031 arm64

Output of java -version

openjdk version "21.0.2" 2024-01-16 LTS OpenJDK Runtime Environment Temurin-21.0.2+13 (build 21.0.2+13-LTS) OpenJDK 64-Bit Server VM Temurin-21.0.2+13 (build 21.0.2+13-LTS, mixed mode)

Quarkus version or git rev

3.8.3

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

Gradle 8.5

Additional information

No response

@rdehuyss rdehuyss added the kind/bug Something isn't working label Apr 30, 2024
Copy link

quarkus-bot bot commented Apr 30, 2024

/cc @Sanne (core), @aloubyansky (core), @geoand (core), @gsmet (core), @radcortez (core), @stuartwdouglas (core)

@gastaldi gastaldi added the area/gradle Gradle label Apr 30, 2024
stuartwdouglas added a commit to stuartwdouglas/quarkus that referenced this issue Apr 30, 2024
Previously if the resources were in the same PathTree only one would be
returned.

Fixes quarkusio#40371
@quarkus-bot quarkus-bot bot added this to the 3.11 - main milestone May 1, 2024
@rdehuyss
Copy link
Contributor Author

rdehuyss commented May 2, 2024

🙏 for fixing this so fast and back porting! ❤️

@gsmet gsmet modified the milestones: 3.11 - main, 3.10.1 May 10, 2024
gsmet pushed a commit to gsmet/quarkus that referenced this issue May 10, 2024
Previously if the resources were in the same PathTree only one would be
returned.

Fixes quarkusio#40371

(cherry picked from commit 9daa467)
@gsmet gsmet modified the milestones: 3.10.1, 3.8.5 May 22, 2024
gsmet pushed a commit to gsmet/quarkus that referenced this issue May 22, 2024
Previously if the resources were in the same PathTree only one would be
returned.

Fixes quarkusio#40371

(cherry picked from commit 9daa467)
gsmet pushed a commit to gsmet/quarkus that referenced this issue May 22, 2024
Previously if the resources were in the same PathTree only one would be
returned.

Fixes quarkusio#40371

(cherry picked from commit 9daa467)
gsmet pushed a commit to gsmet/quarkus that referenced this issue May 23, 2024
Previously if the resources were in the same PathTree only one would be
returned.

Fixes quarkusio#40371

(cherry picked from commit 9daa467)
gsmet pushed a commit to gsmet/quarkus that referenced this issue Jun 4, 2024
Previously if the resources were in the same PathTree only one would be
returned.

Fixes quarkusio#40371

(cherry picked from commit 9daa467)
holly-cummins pushed a commit to holly-cummins/quarkus that referenced this issue Jul 31, 2024
Previously if the resources were in the same PathTree only one would be
returned.

Fixes quarkusio#40371
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core area/gradle Gradle kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants