You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2012/04/08 00:27:57 UTC
svn commit: r1310893 -
/lucene/dev/trunk/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java
Author: uschindler
Date: Sat Apr 7 22:27:57 2012
New Revision: 1310893
URL: http://svn.apache.org/viewvc?rev=1310893&view=rev
Log:
LUCENE-3919: Die, context class loader, die. Also don't initialize (run static ctors) unrelated classes!
@UweSays: "If you get the context classloader from a thread, in most cases you are doing something wrong because you don't understand how Java classloading works."
Modified:
lucene/dev/trunk/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java
Modified: lucene/dev/trunk/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java?rev=1310893&r1=1310892&r2=1310893&view=diff
==============================================================================
--- lucene/dev/trunk/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java (original)
+++ lucene/dev/trunk/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java Sat Apr 7 22:27:57 2012
@@ -55,7 +55,8 @@ public class TestRandomChains extends Ba
@BeforeClass
public static void beforeClass() throws Exception {
- List<Class<?>> analysisClasses = getClassesForPackage("org.apache.lucene.analysis");
+ List<Class<?>> analysisClasses = new ArrayList<Class<?>>();
+ getClassesForPackage("org.apache.lucene.analysis", analysisClasses);
tokenizers = new ArrayList<Class<? extends Tokenizer>>();
tokenfilters = new ArrayList<Class<? extends TokenFilter>>();
charfilters = new ArrayList<Class<? extends CharStream>>();
@@ -274,17 +275,16 @@ public class TestRandomChains extends Ba
}
}
- private static List<Class<?>> getClassesForPackage(String pckgname) throws Exception {
- ArrayList<File> directories = new ArrayList<File>();
- ClassLoader cld = Thread.currentThread().getContextClassLoader();
- String path = pckgname.replace('.', '/');
- Enumeration<URL> resources = cld.getResources(path);
+ private static void getClassesForPackage(String pckgname, List<Class<?>> classes) throws Exception {
+ final ArrayList<File> directories = new ArrayList<File>();
+ final ClassLoader cld = TestRandomChains.class.getClassLoader();
+ final String path = pckgname.replace('.', '/');
+ final Enumeration<URL> resources = cld.getResources(path);
while (resources.hasMoreElements()) {
final File f = new File(resources.nextElement().toURI());
directories.add(f);
}
- ArrayList<Class<?>> classes = new ArrayList<Class<?>>();
for (File directory : directories) {
if (directory.exists()) {
String[] files = directory.list();
@@ -292,19 +292,20 @@ public class TestRandomChains extends Ba
if (new File(directory, file).isDirectory()) {
// recurse
String subPackage = pckgname + "." + file;
- classes.addAll(getClassesForPackage(subPackage));
+ getClassesForPackage(subPackage, classes);
}
if (file.endsWith(".class")) {
- String clazzName = file.substring(0, file.length() - 6);
- // exclude Test classes that happen to be in these packages.
- // class.ForName'ing some of them can cause trouble.
- if (!clazzName.endsWith("Test") && !clazzName.startsWith("Test")) {
- classes.add(Class.forName(pckgname + '.' + clazzName));
- }
+ String clazzName = file.substring(0, file.length() - 6);
+ // exclude Test classes that happen to be in these packages.
+ // class.ForName'ing some of them can cause trouble.
+ if (!clazzName.endsWith("Test") && !clazzName.startsWith("Test")) {
+ // Don't run static initializers, as we won't use most of them.
+ // Java will do that automatically once accessed/instantiated.
+ classes.add(Class.forName(pckgname + '.' + clazzName, false, cld));
+ }
}
}
}
}
- return classes;
}
}