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

Fix potential NPE in ClassPathElement.getResources #40430

Closed

Conversation

jamesnetherton
Copy link
Contributor

Fixes an issue observed on the Camel Quarkus nightly build with Quarkus 999-SNAPSHOT.

The following change causes the camel-quarkus-kotlin-dsl tests to fail:

9daa467

Caused by: java.lang.NullPointerException
	at java.base/java.util.Objects.requireNonNull(Objects.java:233)
	at java.base/java.util.ImmutableCollections$List12.<init>(ImmutableCollections.java:563)
	at java.base/java.util.List.of(List.java:937)
	at io.quarkus.bootstrap.classloading.ClassPathElement.getResources(ClassPathElement.java:147)
	at io.quarkus.bootstrap.classloading.QuarkusClassLoader.getResources(QuarkusClassLoader.java:270)
	at io.quarkus.bootstrap.classloading.QuarkusClassLoader.getResources(QuarkusClassLoader.java:210)
	at kotlin.script.experimental.jvm.util.JvmClasspathUtilKt.rawClassPathFromKeyResourcePath(jvmClasspathUtil.kt:139)
	at kotlin.script.experimental.jvm.util.JvmClasspathUtilKt.classPathFromTypicalResourceUrls(jvmClasspathUtil.kt:152)
	at kotlin.script.experimental.jvm.util.JvmClasspathUtilKt$classpathFromClassloader$1.invoke(jvmClasspathUtil.kt:96)
	at kotlin.script.experimental.jvm.util.JvmClasspathUtilKt$classpathFromClassloader$1.invoke(jvmClasspathUtil.kt:77)

I'm no expert in this area but the change was enough to get the tests passing again.

@quarkus-bot quarkus-bot bot added the area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins label May 3, 2024
Copy link
Member

@Sanne Sanne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good in principle but I'd patch the case of List<ClassPathResource> getResources to be a bit safer, if you don't mind?

(see comments)

Thanks!

@@ -144,6 +144,10 @@ public void close() {
};

default List<ClassPathResource> getResources(String name) {
return List.of(getResource(name));
ClassPathResource resource = getResource(name);
if (resource != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right I think this is necessary. We might want to clarify the javadoc on getResource: I see many other uses are implementing the nullcheck, so they expect it, but the contract could be clarified.

for (var res : resList) {
if (res != null) {
resources.add(res.getUrl());
if (resList != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case while the fix is probably fine, it would be better to track down which implementations of List<ClassPathResource> getResources(String name) actually return null, and have them return an empty list.

I see the implementation in PathTreeClassPathElement does that - wouldn't you rather patch the implementation?

It feels wrong to me in this case as it could more safely return an empty list.

@quarkus-bot
Copy link

quarkus-bot bot commented May 3, 2024

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit 910b9c3.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

You can consult the Develocity build scans.

@jamesnetherton
Copy link
Contributor Author

jamesnetherton commented May 3, 2024

On reflection, I think I'd prefer to leave this one to the experts. I'll open an issue.

Edit - here's the issue #40438.

@quarkus-bot quarkus-bot bot added the triage/invalid This doesn't seem right label May 3, 2024
@Sanne
Copy link
Member

Sanne commented May 3, 2024

On reflection, I think I'd prefer to leave this one to the experts. I'll open an issue.

Edit - here's the issue #40438.

@jamesnetherton you were so close! Are you sure you don't want to give it a shot?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins triage/invalid This doesn't seem right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants