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

[logging] ContextClassLoader may load Log impl from wrong context in JDK 1.4

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Cannot Reproduce
    • 1.0.3
    • None
    • None
    • Operating System: other
      Platform: All

    • 28291

    Description

      The static method org.apache.commons.logging.LogFactory#getContextClassLoader
      will return the ClassLoader for the currently executing thread
      Thread.currentThread(). If this ClassLoader is different from the ClassLoader
      which loaded org.apache.commons.logging.Log, the implementing class cannot be
      cast to Log.

      This results in Log.class.isAssignableFrom(logClass) returning false even
      though logClass implements Log. In turn, this causes
      org.apache.commons.logging.impl.LogFactoryImpl#getLogConstructor() to
      incorrectly throw the exception "Class " + logClass + " does not implement Log"

      The solution is to use the same ClassLoader that was used to load
      org.apache.commons.logging.Log.

      On line 463 of LogFactoryImpl.java, replace the line:
      ClassLoader threadCL = getContextClassLoader();

      with:
      ClassLoader threadCL = Log.class.getClassLoader();

      The only was I am aware of to reproduce this bug is to write a Jakarta Cactus
      Test Suite and run the test using junit.swingui.TestRunner.main or
      junit.awtui.TestRunner.main. Because the Thread has a different
      ContextClassLoader, commons-logging will fail to instantiate the Log
      implementation.

      Attachments

        Activity

          People

            Unassigned Unassigned
            chriseldredge@comcast.net Chris Eldredge
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: