提交 bae98769 authored 作者: Thomas Mueller's avatar Thomas Mueller

Fix tests

上级 e2745e36
...@@ -21,7 +21,6 @@ import java.util.Arrays; ...@@ -21,7 +21,6 @@ import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
...@@ -63,10 +62,12 @@ public class Utils { ...@@ -63,10 +62,12 @@ public class Utils {
private static boolean allowAllClasses; private static boolean allowAllClasses;
private static HashSet<String> allowedClassNames; private static HashSet<String> allowedClassNames;
/** /**
* In order to manage more than one class loader * In order to manage more than one class loader
*/ */
private static List<ClassFactory> userClassFactories = new ArrayList<ClassFactory>(); private static ArrayList<ClassFactory> userClassFactories = new ArrayList<ClassFactory>();
private static String[] allowedClassNamePrefixes; private static String[] allowedClassNamePrefixes;
static { static {
...@@ -86,18 +87,29 @@ public class Utils { ...@@ -86,18 +87,29 @@ public class Utils {
/** /**
* Add a class factory in order to manage more than one class loader. * Add a class factory in order to manage more than one class loader.
*
* @param classFactory An object that implements ClassFactory * @param classFactory An object that implements ClassFactory
*/ */
public static void addClassFactory(ClassFactory classFactory) { public static void addClassFactory(ClassFactory classFactory) {
userClassFactories.add(classFactory); getUserClassFactories().add(classFactory);
} }
/** /**
* Remove a class factory * Remove a class factory
*
* @param classFactory Already inserted class factory instance * @param classFactory Already inserted class factory instance
*/ */
public static void removeClassFactory(ClassFactory classFactory) { public static void removeClassFactory(ClassFactory classFactory) {
userClassFactories.remove(classFactory); getUserClassFactories().remove(classFactory);
}
private static ArrayList<ClassFactory> getUserClassFactories() {
if (userClassFactories == null) {
// initially, it is empty
// but Apache Tomcat may clear the fields as well
userClassFactories = new ArrayList<ClassFactory>();
}
return userClassFactories;
} }
private static int readInt(byte[] buff, int pos) { private static int readInt(byte[] buff, int pos) {
...@@ -592,7 +604,7 @@ public class Utils { ...@@ -592,7 +604,7 @@ public class Utils {
} }
} }
// Use provided class factory first. // Use provided class factory first.
for (ClassFactory classFactory : userClassFactories) { for (ClassFactory classFactory : getUserClassFactories()) {
if (classFactory.match(className)) { if (classFactory.match(className)) {
try { try {
Class<?> userClass = classFactory.loadClass(className); Class<?> userClass = classFactory.loadClass(className);
......
...@@ -42,6 +42,7 @@ public class TestClearReferences extends TestBase { ...@@ -42,6 +42,7 @@ public class TestClearReferences extends TestBase {
"org.h2.util.StringUtils.softCache", "org.h2.util.StringUtils.softCache",
"org.h2.util.Utils.allowedClassNames", "org.h2.util.Utils.allowedClassNames",
"org.h2.util.Utils.allowedClassNamePrefixes", "org.h2.util.Utils.allowedClassNamePrefixes",
"org.h2.util.Utils.userClassFactories",
"org.h2.value.CompareMode.lastUsed", "org.h2.value.CompareMode.lastUsed",
"org.h2.value.Value.softCache", "org.h2.value.Value.softCache",
}; };
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论