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

Add missing normalization, cache normalization #974

Merged
merged 1 commit into from
Sep 7, 2024
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 @@ -512,10 +512,7 @@ private static boolean hasRegularCodeSource(URL url) {

private static Path getCodeSource(URL url, String fileName) {
try {
Path ret = UrlUtil.getCodeSource(url, fileName);
assert ret.equals(LoaderUtil.normalizeExistingPath(ret)); // ret should already be normalized

return ret;
return LoaderUtil.normalizeExistingPath(UrlUtil.getCodeSource(url, fileName));
} catch (UrlConversionException e) {
throw ExceptionUtil.wrap(e);
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/net/fabricmc/loader/impl/util/LoaderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;

public final class LoaderUtil {
private static final ConcurrentMap<Path, Path> pathNormalizationCache = new ConcurrentHashMap<>();

public static String getClassFileName(String className) {
return className.replace('.', '/').concat(".class");
}
Expand All @@ -40,6 +44,10 @@ public static Path normalizePath(Path path) {
}

public static Path normalizeExistingPath(Path path) {
return pathNormalizationCache.computeIfAbsent(path, LoaderUtil::normalizeExistingPath0);
}

private static Path normalizeExistingPath0(Path path) {
try {
return path.toRealPath();
} catch (IOException e) {
Expand Down
Loading