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 issue with fast-jar loading of top-level directories #23598

Merged
merged 1 commit into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ private ClassLoadingResource[] getClassLoadingResources(final String name) {
dirName = "";
}
if (!dirName.equals(name) && fullyIndexedDirectories.contains(dirName)) {
if (dirName.isEmpty()) {
return resourceDirectoryMap.get(name);
}
// If we arrive here, we know that resource being queried belongs to one of the fully indexed directories
// Had that resource existed however, it would have been present in directlyIndexedResourcesIndexMap
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.acme;

import javax.ws.rs.QueryParam;
import org.apache.commons.io.IOUtils;

import javax.ws.rs.GET;
Expand Down Expand Up @@ -32,6 +33,7 @@ public String readClassPathResources() {
() -> assertCorrectExactFileLocation(),
() -> assertInvalidDirectory(),
() -> assertCorrectDirectory(),
() -> assertTopLevelDirectory(),
() -> assertMultiRelease()
);
}
Expand Down Expand Up @@ -160,6 +162,22 @@ private String assertCorrectDirectory() {
}
}

private String assertTopLevelDirectory() {
final String testType = "top-level-directory";
try {
Enumeration<URL> directoryEnumeration = this.getClass().getClassLoader().getResources("assets");
List<URL> directoryURLList = urlList(directoryEnumeration);
if (directoryURLList.size() != 1) {
return errorResult(testType, "wrong number of directory urls");
}

return SUCCESS;
} catch (Exception e) {
e.printStackTrace();
return errorResult(testType, "exception during resolution of resource");
}
}

private List<URL> urlList(Enumeration<URL> enumeration) {
if (enumeration == null) {
return Collections.emptyList();
Expand Down