-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fix potential NPE in ClassPathElement.getResources #40430
Conversation
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.
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) { |
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.
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) { |
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.
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.
Status for workflow
|
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? |
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
I'm no expert in this area but the change was enough to get the tests passing again.