From aa5ace7d372daa8fcd2a367929b4868e4cd42041 Mon Sep 17 00:00:00 2001 From: Costin Manolache Date: Thu, 22 Aug 2002 17:09:05 +0000 Subject: [PATCH] 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 --- src/main/org/apache/tools/ant/AntClassLoader.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/org/apache/tools/ant/AntClassLoader.java b/src/main/org/apache/tools/ant/AntClassLoader.java index 2213e7c24..4c1ac64c9 100644 --- a/src/main/org/apache/tools/ant/AntClassLoader.java +++ b/src/main/org/apache/tools/ant/AntClassLoader.java @@ -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); }