Skip to content

Commit

Permalink
Remove url ref in native scenario
Browse files Browse the repository at this point in the history
Signed-off-by: crazyhzm <crazyhzm@gmail.com>
  • Loading branch information
CrazyHZM committed Mar 28, 2024
1 parent 0c7e32f commit ff4b23a
Showing 1 changed file with 0 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
*/
package org.apache.dubbo.common.utils;

import org.apache.dubbo.common.aot.NativeDetector;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.resource.GlobalResourcesRepository;

import java.io.IOException;
import java.lang.ref.SoftReference;
import java.lang.reflect.Field;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -32,7 +30,6 @@
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;

Expand Down Expand Up @@ -81,15 +78,9 @@ public static Set<URL> loadResources(String fileName, ClassLoader currentClassLo
Enumeration<URL> urls;
try {
urls = currentClassLoader.getResources(fileName);
boolean isNative = NativeDetector.inNativeImage();
if (urls != null) {
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
if (isNative) {
// In native mode, the address of each URL is the same instead of different paths, so it is
// necessary to set the ref to make it different
setRef(url);
}
set.add(url);
}
}
Expand All @@ -113,15 +104,6 @@ public static void destroy() {
}
}

private static void setRef(URL url) {
try {
Field field = URL.class.getDeclaredField("ref");
field.setAccessible(true);
field.set(url, UUID.randomUUID().toString());
} catch (Throwable ignore) {
}
}

// for test
protected static SoftReference<Map<ClassLoader, Map<String, Set<URL>>>> getClassLoaderResourcesCache() {
return classLoaderResourcesCache;
Expand Down

0 comments on commit ff4b23a

Please sign in to comment.