Uploaded image for project: 'Commons Logging'
  1. Commons Logging
  2. LOGGING-7

Can't locate classloader when creating a new LogFactory

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • None
    • None
    • None
    • Operating System: All
      Platform: PC

    • 14439

    Description

      When running WebSphere 5.0 Early Adopters using the Sysdeo Tomcat plugin in
      debug mode I discovered that the LogFactory can't locate a classloader to
      create new Factories. A call to LogFactory.class.getClassLoader()
      returns 'null'. As of the SDK documentation this may be tha case if the
      bootstrap has loaded the class. I thus suggest the following code for the
      newFactory method taken from v1.0.2 of the common logging API:

      /**

      • Return a new instance of the specified <code>LogFactory</code>
      • implementation class, loaded by the specified class loader.
      • If that fails, try the class loader used to load this
      • (abstract) LogFactory.
        *
      • @param factoryClass Fully qualified name of the <code>LogFactory</code>
      • implementation class
      • @param classLoader ClassLoader from which to load this class
        *
      • @exception LogConfigurationException if a suitable instance
      • cannot be created
        */
        protected static LogFactory newFactory(String factoryClass,
        ClassLoader classLoader)
        throws LogConfigurationException
        {

      try {
      if (classLoader == null)
      classLoader = LogFactory.class.getClassLoader();
      Class clazz = null;
      try {
      // #FIX: RBA
      // may be null in case the classloader is the bootstrap
      loader
      if(classLoader == null)

      { // try general load clazz = Class.forName(factoryClass); }

      else

      { // first the thread class loader clazz = classLoader.loadClass(factoryClass); }

      } catch (ClassNotFoundException ex) {
      // if this failed (i.e. no implementation is
      // found in the webapp), try the caller's loader
      // if we haven't already...
      if (classLoader != LogFactory.class.getClassLoader()) {
      classLoader = LogFactory.class.getClassLoader();

      if(classLoader == null)

      { // try general load clazz = Class.forName(factoryClass); }

      else

      { clazz = classLoader.loadClass(factoryClass); }

      }
      }

      LogFactory factory = (LogFactory)clazz.newInstance();

      return factory;
      } catch (Exception e)

      { throw new LogConfigurationException(e); }

      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            bargezi@csi.com Roman Bargezi
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: