Browse Source

Few fixes ( I hope it won't brake anything ).

Added 'org.sax' and 'sun.reflect' to the list of system pacakges. There are
problems when using JDK1.4 with 'endorsed' not set up corectly. This allows
using a different parser, but doesn't allow the overriting of system classes.

Made loadClass synchronized. Yes, it must be - there is a race condition,
we check if the class was not loaded and then load it, but 2 threads
may end up loading the class, and the second will get an exception.
This happen when using tomcat in ant for example - probably other
multithreaded tasks as well.

I left the stack trace in, it shouldn't happen in normal cases ( AFAIK ),
but when something strange happens it helps a lot to know what was wrong.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273239 13f79535-47bb-0310-9956-ffa450edef68
master
Costin Manolache 23 years ago
parent
commit
aa5ace7d37
1 changed files with 8 additions and 2 deletions
  1. +8
    -2
      src/main/org/apache/tools/ant/AntClassLoader.java

+ 8
- 2
src/main/org/apache/tools/ant/AntClassLoader.java View File

@@ -323,6 +323,8 @@ public class AntClassLoader extends ClassLoader implements BuildListener {
//addJavaLibraries();
addSystemPackageRoot("java");
addSystemPackageRoot("javax");
addSystemPackageRoot("org.xml.sax");
addSystemPackageRoot("sun.reflect");
}


@@ -906,8 +908,11 @@ public class AntClassLoader extends ClassLoader implements BuildListener {
* on the system classpath (when not in isolated mode) or this loader's
* classpath.
*/
protected Class loadClass(String classname, boolean resolve)
protected synchronized Class loadClass(String classname, boolean resolve)
throws ClassNotFoundException {
// 'sync' is needed - otherwise 2 threads can load the same class
// twice, resulting in LinkageError: duplicated class definition.
// findLoadedClass avoids that, but without sync it won't work.

Class theClass = findLoadedClass(classname);
if (theClass != null) {
@@ -1059,12 +1064,13 @@ public class AntClassLoader extends ClassLoader implements BuildListener {
try {
stream = getResourceStream(pathComponent, classFilename);
if (stream != null) {
// System.out.println("Found " + classFilename + " in " + pathComponent );
return getClassFromStream(stream, name);
}
} catch (SecurityException se) {
throw se;
} catch (IOException ioe) {
// ioe.printStackTrace();
ioe.printStackTrace();
log("Exception reading component " + pathComponent ,
Project.MSG_VERBOSE);
}


Loading…
Cancel
Save