Skip to content

Commit

Permalink
Prevent potential NPEs in QuarkusClassLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Sep 20, 2022
1 parent 0212a4c commit 9bd277d
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,14 @@ public Enumeration<URL> getResources(String unsanitisedName, boolean parentAlrea
}
}
//TODO: in theory resources could have been added in dev mode
//but I don't thing this really matters for this code path
//but I don't think this really matters for this code path
ClassPathElement[] providers = state.loadableResources.get(name);
if (providers != null) {
for (ClassPathElement element : providers) {
ClassPathResource res = element.getResource(name);
if (res == null) {
continue;
}
//if the requested name ends with a trailing / we make sure
//that the resource is a directory, and return a URL that ends with a /
//this matches the behaviour of URLClassLoader
Expand Down Expand Up @@ -351,7 +354,11 @@ public URL getResource(String unsanitisedName) {
if (name.endsWith(".class") && !endsWithTrailingSlash) {
ClassPathElement[] providers = state.loadableResources.get(name);
if (providers != null) {
return providers[0].getResource(name).getUrl();
ClassPathResource resource = providers[0].getResource(name);
if (resource == null) {
return null;
}
return resource.getUrl();
}
} else {
for (ClassPathElement i : elements) {
Expand Down Expand Up @@ -391,7 +398,11 @@ public InputStream getResourceAsStream(String unsanitisedName) {
if (name.endsWith(".class")) {
ClassPathElement[] providers = state.loadableResources.get(name);
if (providers != null) {
return new ByteArrayInputStream(providers[0].getResource(name).getData());
ClassPathResource resource = providers[0].getResource(name);
if (resource == null) {
return null;
}
return new ByteArrayInputStream(resource.getData());
}
} else {
for (ClassPathElement i : elements) {
Expand Down

0 comments on commit 9bd277d

Please sign in to comment.