diff --git a/CHANGELOG.md b/CHANGELOG.md index e480ed309..267a1e36a 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,12 +3,13 @@ ------------------------------------------------------------------------------------------------------------- -# 5.8.10.M1 (2022-11-03) +# 5.8.10.M1 (2022-11-08) ### 🐣新特性 * 【http 】 HttpResponse增加getFileNameFromDisposition方法(pr#2676@Github) * 【core 】 FileUtil.copy,当来源为文件时,返回文件而非目录(issue#I5YCVL@Gitee) * 【db 】 DialectFactory增加identifyDriver重载(issue#I5YWI6@Gitee) +* 【core 】 去除ClassloaderUtil的Cache(issue#I5YWI6@Gitee) ### 🐞Bug修复 * 【db 】 修复分页时order by截断问题(issue#I5X6FM@Gitee) diff --git a/hutool-core/src/main/java/cn/hutool/core/util/ClassLoaderUtil.java b/hutool-core/src/main/java/cn/hutool/core/util/ClassLoaderUtil.java index d6555bc7e..fbf268727 100755 --- a/hutool-core/src/main/java/cn/hutool/core/util/ClassLoaderUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/util/ClassLoaderUtil.java @@ -4,9 +4,7 @@ import cn.hutool.core.convert.BasicType; import cn.hutool.core.exceptions.UtilException; import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.JarClassLoader; -import cn.hutool.core.lang.Pair; import cn.hutool.core.map.SafeConcurrentHashMap; -import cn.hutool.core.map.WeakConcurrentMap; import cn.hutool.core.text.CharPool; import java.io.File; @@ -50,10 +48,9 @@ public class ClassLoaderUtil { * 原始类型名和其class对应表,例如:int =》 int.class */ private static final Map> PRIMITIVE_TYPE_NAME_MAP = new SafeConcurrentHashMap<>(32); - private static final Map, Class> CLASS_CACHE = new WeakConcurrentMap<>(); static { - List> primitiveTypes = new ArrayList<>(32); + final List> primitiveTypes = new ArrayList<>(32); // 加入原始类型 primitiveTypes.addAll(BasicType.PRIMITIVE_WRAPPER_MAP.keySet()); // 加入原始类型数组类型 @@ -66,7 +63,7 @@ public class ClassLoaderUtil { primitiveTypes.add(long[].class); primitiveTypes.add(short[].class); primitiveTypes.add(void.class); - for (Class primitiveType : primitiveTypes) { + for (final Class primitiveType : primitiveTypes) { PRIMITIVE_TYPE_NAME_MAP.put(primitiveType.getName(), primitiveType); } } @@ -197,9 +194,7 @@ public class ClassLoaderUtil { // 加载原始类型和缓存中的类 Class clazz = loadPrimitiveClass(name); if (clazz == null) { - final String finalName = name; - final ClassLoader finalClassLoader = classLoader; - clazz = CLASS_CACHE.computeIfAbsent(Pair.of(name, classLoader), (key)-> doLoadClass(finalName, finalClassLoader, isInitialized)); + clazz = doLoadClass(name, classLoader, isInitialized); } return clazz; } diff --git a/hutool-core/src/test/java/cn/hutool/core/util/ClassLoaderUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/ClassLoaderUtilTest.java index 12a4382e0..079e731d1 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/ClassLoaderUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/ClassLoaderUtilTest.java @@ -4,12 +4,12 @@ import org.junit.Assert; import org.junit.Test; public class ClassLoaderUtilTest { - + @Test public void loadClassTest() { String name = ClassLoaderUtil.loadClass("java.lang.Thread.State").getName(); Assert.assertEquals("java.lang.Thread$State", name); - + name = ClassLoaderUtil.loadClass("java.lang.Thread$State").getName(); Assert.assertEquals("java.lang.Thread$State", name); }