neilg 2003/02/19 07:04:05
Modified: java/src/org/apache/xerces/util ObjectFactory.java
SecuritySupport.java SecuritySupport12.java
Log:
additional fix for bug 16674; thanks again to Igor Malinin
Revision Changes Path
1.13 +48 -17 xml-xerces/java/src/org/apache/xerces/util/ObjectFactory.java
Index: ObjectFactory.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/util/ObjectFactory.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- ObjectFactory.java 17 Feb 2003 21:43:21 -0000 1.12
+++ ObjectFactory.java 19 Feb 2003 15:04:04 -0000 1.13
@@ -282,7 +282,7 @@
/**
* Figure out which ClassLoader to use. For JDK 1.2 and later use
* the context ClassLoader.
- */
+ */
public static ClassLoader findClassLoader()
throws ConfigurationError
{
@@ -290,22 +290,53 @@
// Figure out which ClassLoader to use for loading the provider
// class. If there is a Context ClassLoader then use it.
- ClassLoader cl = ss.getContextClassLoader();
- if (cl == null || cl == ss.getSystemClassLoader()) {
- // Assert: we are on JDK 1.1 or we have no Context ClassLoader
- // so use the current ClassLoader or we have default (system)
- // Context ClassLoader so extend to current ClassLoader (normal
- // classloader will delegate back to system ClassLoader first)
- cl = ObjectFactory.class.getClassLoader();
- }
-
- if (cl == null) {
- // Assert: we are on JDK 1.1 or we are on JDK 1.2 and loaded
- // by bootstrap ClassLoader so extend to System ClassLoader
- cl = ss.getSystemClassLoader();
- }
+ ClassLoader context = ss.getContextClassLoader();
+ ClassLoader system = ss.getSystemClassLoader();
- return cl;
+ ClassLoader chain = system;
+ while (true) {
+ if (context == chain) {
+ // Assert: we are on JDK 1.1 or we have no Context ClassLoader
+ // or any Context ClassLoader in chain of system classloader
+ // (including extension ClassLoader) so extend to widest
+ // ClassLoader (always look in system ClassLoader if Xerces
+ // is in boot/extension/system classpath and in current
+ // ClassLoader otherwise); normal classloaders delegate
+ // back to system ClassLoader first so this widening doesn't
+ // change the fact that context ClassLoader will be consulted
+ ClassLoader current = ObjectFactory.class.getClassLoader();
+
+ chain = system;
+ while (true) {
+ if (current == chain) {
+ // Assert: Current ClassLoader in chain of
+ // boot/extension/system ClassLoaders
+ return system;
+ }
+ if (chain == null) {
+ break;
+ }
+ chain = ss.getParentClassLoader(chain);
+ }
+
+ // Assert: Current ClassLoader not in chain of
+ // boot/extension/system ClassLoaders
+ return current;
+ }
+
+ if (chain == null) {
+ // boot ClassLoader reached
+ break;
+ }
+
+ // Check for any extension ClassLoaders in chain up to
+ // boot ClassLoader
+ chain = ss.getParentClassLoader(chain);
+ };
+
+ // Assert: Context ClassLoader not in chain of
+ // boot/extension/system ClassLoaders
+ return context;
} // findClassLoader():ClassLoader
/**
1.4 +4 -0 xml-xerces/java/src/org/apache/xerces/util/SecuritySupport.java
Index: SecuritySupport.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/util/SecuritySupport.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SecuritySupport.java 17 Feb 2003 21:43:21 -0000 1.3
+++ SecuritySupport.java 19 Feb 2003 15:04:04 -0000 1.4
@@ -120,6 +120,10 @@
return null;
}
+ public ClassLoader getParentClassLoader(ClassLoader cl) {
+ return null;
+ }
+
public String getSystemProperty(String propName) {
return System.getProperty(propName);
}
1.4 +16 -0
xml-xerces/java/src/org/apache/xerces/util/SecuritySupport12.java
Index: SecuritySupport12.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/util/SecuritySupport12.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SecuritySupport12.java 17 Feb 2003 21:43:21 -0000 1.3
+++ SecuritySupport12.java 19 Feb 2003 15:04:04 -0000 1.4
@@ -93,6 +93,22 @@
});
}
+ public ClassLoader getParentClassLoader(final ClassLoader cl) {
+ return (ClassLoader)
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ ClassLoader parent = null;
+ try {
+ parent = cl.getParent();
+ } catch (SecurityException ex) {}
+
+ // eliminate loops in case of the boot
+ // ClassLoader returning itself as a parent
+ return (parent == cl) ? null : parent;
+ }
+ });
+ }
+
public String getSystemProperty(final String propName) {
return (String)
AccessController.doPrivileged(new PrivilegedAction() {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]