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

ClasspathDirectory.directoryList(): check parent package first #3445 #3450

Merged
merged 1 commit into from
Dec 13, 2024
Merged
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 @@ -78,6 +78,25 @@ public class ClasspathDirectory extends ClasspathLocation {
}

private String[] directoryList(String qualifiedPackageName) {
String qualifiedPackagePath = qualifiedPackageName.replace('/', File.separatorChar);
// must protect against a case insensitive File call
// walk the qualifiedPackageName backwards looking for an uppercase character before the '/'
int index = qualifiedPackagePath.length();
int last = qualifiedPackagePath.lastIndexOf(File.separatorChar);
while (--index > last && !ScannerHelper.isUpperCase(qualifiedPackagePath.charAt(index))) {
/* empty */}
if (index > last) {
if (last == -1) {
if (!doesFileExist(qualifiedPackagePath, Util.EMPTY_STRING))
return null;
} else {
String packageName = qualifiedPackagePath.substring(last + 1);
String parentPackage = qualifiedPackagePath.substring(0, last);
if (!doesFileExist(packageName, parentPackage))
return null;
}
}

String[] cached = this.directoryCache.computeIfAbsent(qualifiedPackageName, this::computeDirectoryList);
if (cached == this.missingPackageHolder) {
return null; // package exists in another classpath directory or jar
Expand All @@ -89,24 +108,7 @@ private String[] computeDirectoryList(String qualifiedPackageName) {
String qualifiedPackagePath = qualifiedPackageName.replace('/', File.separatorChar);
File dir = new File(this.path + qualifiedPackagePath);
String[] dirList = dir.list();
notFound: if (dirList != null) { // if isDirectory
// must protect against a case insensitive File call
// walk the qualifiedPackageName backwards looking for an uppercase character before the '/'
int index = qualifiedPackagePath.length();
int last = qualifiedPackagePath.lastIndexOf(File.separatorChar);
while (--index > last && !ScannerHelper.isUpperCase(qualifiedPackagePath.charAt(index))) {
/* empty */}
if (index > last) {
if (last == -1) {
if (!doesFileExist(qualifiedPackagePath, Util.EMPTY_STRING))
break notFound;
} else {
String packageName = qualifiedPackagePath.substring(last + 1);
String parentPackage = qualifiedPackagePath.substring(0, last);
if (!doesFileExist(packageName, parentPackage))
break notFound;
}
}
if (dirList != null) { // if isDirectory
if (dirList.length == 0) {
dirList = CharOperation.NO_STRINGS;
}
Expand Down
Loading