commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@apache.org
Subject cvs commit: jakarta-commons/logging/src/java/org/apache/commons/logging/impl LogFactoryImpl.java
Date Sat, 06 Mar 2004 21:52:59 GMT
craigmcc    2004/03/06 13:52:59

  Modified:    logging/src/java/org/apache/commons/logging/impl
                        LogFactoryImpl.java
  Log:
  Enhance the error message produced when the isAssignableFrom() check
  in getLogConstructor() fails.  If it is due to the fact that o.a.c.l.Log
  is visible more than once (the typical cause), say this explicitly.
  
  PR:  Bugzilla #25156.
  Submitted by:  Ralf Hauser <hauser AT acm DOT org>
  
  Revision  Changes    Path
  1.33      +24 -3     jakarta-commons/logging/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java
  
  Index: LogFactoryImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- LogFactoryImpl.java	6 Mar 2004 21:25:36 -0000	1.32
  +++ LogFactoryImpl.java	6 Mar 2004 21:52:59 -0000	1.33
  @@ -98,6 +98,13 @@
           "org.apache.commons.logging.log";
   
   
  +    /**
  +     * <p>The name of the {@link Log} interface class.</p>
  +     */
  +    private static final String LOG_INTERFACE =
  +        "org.apache.commons.logging.Log";
  +
  +
       // ----------------------------------------------------- Instance Variables
   
   
  @@ -362,15 +369,29 @@
   
           // Attempt to load the Log implementation class
           Class logClass = null;
  +        Class logInterface = null;
           try {
  +            logInterface = this.getClass().getClassLoader().loadClass
  +                (LOG_INTERFACE);
               logClass = loadClass(logClassName);
               if (logClass == null) {
                   throw new LogConfigurationException
                       ("No suitable Log implementation for " + logClassName);
               }
  -            if (!Log.class.isAssignableFrom(logClass)) {
  +            if (!logInterface.isAssignableFrom(logClass)) {
  +                Class interfaces[] = logClass.getInterfaces();
  +                for (int i = 0; i < interfaces.length; i++) {
  +                    if (LOG_INTERFACE.equals(interfaces[i].getName())) {
  +                        throw new LogConfigurationException
  +                            ("Invalid class loader hierarchy.  " +
  +                             "You have more than one version of '" +
  +                             LOG_INTERFACE + "' visible, which is " +
  +                             "not allowed.");
  +                    }
  +                }
                   throw new LogConfigurationException
  -                    ("Class " + logClassName + " does not implement Log");
  +                    ("Class " + logClassName + " does not implement '" +
  +                     LOG_INTERFACE + "'.");
               }
           } catch (Throwable t) {
               throw new LogConfigurationException(t);
  
  
  

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


Mime
View raw message