neilg       2003/02/17 13:43:22

  Modified:    java/src/org/apache/xerces/util ObjectFactory.java
                        SecuritySupport.java SecuritySupport12.java
  Log:
  fix for bug 16674; thanks to Igor Malinin
  
  Revision  Changes    Path
  1.12      +30 -20    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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ObjectFactory.java        4 Feb 2003 17:00:51 -0000       1.11
  +++ ObjectFactory.java        17 Feb 2003 21:43:21 -0000      1.12
  @@ -64,9 +64,6 @@
   import java.io.BufferedReader;
   import java.io.InputStreamReader;
   
  -import java.lang.reflect.Method;
  -import java.lang.reflect.InvocationTargetException;
  -
   /**
    * This class is duplicated for each JAXP subpackage so keep it in sync.
    * It is package private and therefore is not exposed as part of the JAXP
  @@ -294,13 +291,21 @@
           // 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) {
  +        if (cl == null || cl == ss.getSystemClassLoader()) {
               // Assert: we are on JDK 1.1 or we have no Context ClassLoader
  -            // so use the current 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();
           }
  -        return cl;
   
  +        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();
  +        }
  +
  +        return cl;
       } // findClassLoader():ClassLoader
   
       /**
  @@ -352,13 +357,21 @@
               } catch (ClassNotFoundException x) {
                   if (doFallback) {
                       // Fall back to current classloader
  -                    cl = ObjectFactory.class.getClassLoader();
  -                    providerClass = cl.loadClass(className);
  +                    ClassLoader current = ObjectFactory.class.getClassLoader();
  +                    if (current == null) {
  +                        providerClass = Class.forName(className);
  +                    } else if (cl != current) {
  +                        cl = current;
  +                        providerClass = cl.loadClass(className);
  +                    } else {
  +                        throw x;
  +                    }
                   } else {
                       throw x;
                   }
               }
           }
  +
           return providerClass;
       }
   
  @@ -375,20 +388,17 @@
           InputStream is = null;
   
           // First try the Context ClassLoader
  -        ClassLoader cl = ss.getContextClassLoader();
  -        if (cl != null) {
  -            is = ss.getResourceAsStream(cl, serviceId);
  +        ClassLoader cl = findClassLoader();
   
  -            // If no provider found then try the current ClassLoader
  -            if (is == null) {
  -                cl = ObjectFactory.class.getClassLoader();
  +        is = ss.getResourceAsStream(cl, serviceId);
  +
  +        // If no provider found then try the current ClassLoader
  +        if (is == null) {
  +            ClassLoader current = ObjectFactory.class.getClassLoader();
  +            if (cl != current) {
  +                cl = current;
                   is = ss.getResourceAsStream(cl, serviceId);
               }
  -        } else {
  -            // No Context ClassLoader or JDK 1.1 so try the current
  -            // ClassLoader
  -            cl = ObjectFactory.class.getClassLoader();
  -            is = ss.getResourceAsStream(cl, serviceId);
           }
   
           if (is == null) {
  
  
  
  1.3       +4 -2      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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SecuritySupport.java      24 Jan 2003 17:20:11 -0000      1.2
  +++ SecuritySupport.java      17 Feb 2003 21:43:21 -0000      1.3
  @@ -55,8 +55,6 @@
   
   package org.apache.xerces.util;
   
  -import java.lang.reflect.*;
  -import java.net.*;
   import java.io.*;
   
   /**
  @@ -116,6 +114,10 @@
   
       public ClassLoader getContextClassLoader() {
        return null;
  +    }
  +
  +    public ClassLoader getSystemClassLoader() {
  +        return null;
       }
   
       public String getSystemProperty(String propName) {
  
  
  
  1.3       +13 -2     
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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SecuritySupport12.java    24 Jan 2003 17:20:11 -0000      1.2
  +++ SecuritySupport12.java    17 Feb 2003 21:43:21 -0000      1.3
  @@ -56,9 +56,7 @@
   package org.apache.xerces.util;
   
   import java.security.*;
  -import java.net.*;
   import java.io.*;
  -import java.util.*;
   
   /**
    * This class is duplicated for each JAXP subpackage so keep it in sync.
  @@ -80,6 +78,19 @@
                return cl;
            }
        });
  +    }
  +
  +    public ClassLoader getSystemClassLoader() {
  +        return (ClassLoader)
  +            AccessController.doPrivileged(new PrivilegedAction() {
  +                public Object run() {
  +                    ClassLoader cl = null;
  +                    try {
  +                        cl = ClassLoader.getSystemClassLoader();
  +                    } catch (SecurityException ex) {}
  +                    return cl;
  +                }
  +            });
       }
   
       public String getSystemProperty(final String propName) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to