Skip to content

Commit

Permalink
Add missing normalization, cache normalization (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfPlayer1 authored Sep 7, 2024
1 parent 9e6fc1b commit 2908ef3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
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

0 comments on commit 2908ef3

Please sign in to comment.