commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rsi...@apache.org
Subject cvs commit: jakarta-commons/logging/src/java/org/apache/commons/logging LogFactory.java
Date Fri, 13 Dec 2002 16:48:06 GMT
rsitze      2002/12/13 08:48:06

  Modified:    logging/src/java/org/apache/commons/logging LogFactory.java
  Log:
  More doPriv's around ClassLoader.loadClass and Class.forName
  
  Revision  Changes    Path
  1.17      +48 -39    jakarta-commons/logging/src/java/org/apache/commons/logging/LogFactory.java
  
  Index: LogFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/LogFactory.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- LogFactory.java	12 Dec 2002 20:29:16 -0000	1.16
  +++ LogFactory.java	13 Dec 2002 16:48:06 -0000	1.17
  @@ -533,46 +533,55 @@
        * @exception LogConfigurationException if a suitable instance
        *  cannot be created
        */
  -    protected static LogFactory newFactory(String factoryClass,
  -                                           ClassLoader classLoader)
  +    protected static LogFactory newFactory(final String factoryClass,
  +                                           final ClassLoader classLoader)
           throws LogConfigurationException
       {
  -        
  -        try {
  -            if (classLoader != null) {
  -                try {
  -                    // first the given class loader param (thread class loader)
  -                    return (LogFactory)classLoader.loadClass(factoryClass).newInstance();
  -                } catch (ClassNotFoundException ex) {
  -                    if (classLoader == LogFactory.class.getClassLoader()) {
  -                        // Nothing more to try, onwards.
  -                        throw ex;
  +        Object result = AccessController.doPrivileged(
  +            new PrivilegedAction() {
  +                public Object run() {
  +                    try {
  +                        if (classLoader != null) {
  +                            try {
  +                                // first the given class loader param (thread class loader)
  +                                return classLoader.loadClass(factoryClass).newInstance();
  +                            } catch (ClassNotFoundException ex) {
  +                                if (classLoader == LogFactory.class.getClassLoader()) {
  +                                    // Nothing more to try, onwards.
  +                                    throw ex;
  +                                }
  +                                // ignore exception, continue
  +                            } catch (NoClassDefFoundError e) {
  +                                if (classLoader == LogFactory.class.getClassLoader()) {
  +                                    // Nothing more to try, onwards.
  +                                    throw e;
  +                                }
  +                                // ignore exception, continue
  +                            }
  +                        }
  +            
  +                        /* At this point, either classLoader == null, OR
  +                         * classLoader was unable to load factoryClass..
  +                         * try the class loader that loaded this class:
  +                         * LogFactory.getClassLoader().
  +                         * 
  +                         * Notes:
  +                         * a) LogFactory.class.getClassLoader() may return 'null'
  +                         *    if LogFactory is loaded by the bootstrap classloader.
  +                         * b) The Java endorsed library mechanism is instead
  +                         *    Class.forName(factoryClass);
  +                         */
  +                        return (LogFactory)Class.forName(factoryClass).newInstance();
  +                    } catch (Exception e) {
  +                        return new LogConfigurationException(e);
                       }
  -                    // ignore exception, continue
  -                } catch (NoClassDefFoundError e) {
  -                    if (classLoader == LogFactory.class.getClassLoader()) {
  -                        // Nothing more to try, onwards.
  -                        throw e;
  -                    }
  -                    // ignore exception, continue
                   }
  -            }
  +            });
   
  -            /* At this point, either classLoader == null, OR
  -             * classLoader was unable to load factoryClass..
  -             * try the class loader that loaded this class:
  -             * LogFactory.getClassLoader().
  -             * 
  -             * Notes:
  -             * a) LogFactory.class.getClassLoader() may return 'null'
  -             *    if LogFactory is loaded by the bootstrap classloader.
  -             * b) The Java endorsed library mechanism is instead
  -             *    Class.forName(factoryClass);
  -             */
  -            return (LogFactory)Class.forName(factoryClass).newInstance();
  -        } catch (Exception e) {
  -            throw new LogConfigurationException(e);
  -        }
  +        if (result instanceof LogConfigurationException)
  +            throw (LogConfigurationException)result;
  +            
  +        return (LogFactory)result;
       }
       
       private static InputStream getResourceAsStream(final ClassLoader loader,
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message