costin 2002/08/22 10:09:05 Modified: src/main/org/apache/tools/ant AntClassLoader.java Log: 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. Revision Changes Path 1.57 +8 -2 jakarta-ant/src/main/org/apache/tools/ant/AntClassLoader.java Index: AntClassLoader.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/AntClassLoader.java,v retrieving revision 1.56 retrieving revision 1.57 diff -u -r1.56 -r1.57 --- AntClassLoader.java 25 Jul 2002 15:21:01 -0000 1.56 +++ AntClassLoader.java 22 Aug 2002 17:09:05 -0000 1.57 @@ -323,6 +323,8 @@ //addJavaLibraries(); addSystemPackageRoot("java"); addSystemPackageRoot("javax"); + addSystemPackageRoot("org.xml.sax"); + addSystemPackageRoot("sun.reflect"); } @@ -906,8 +908,11 @@ * 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 @@ 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); }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>