Commons Logging
  1. Commons Logging
  2. LOGGING-45

Default LogFactory Implementation fails for Log4J : ClassCastException

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0
    • Fix Version/s: 1.0.3
    • Labels:
      None
    • Environment:

      Operating System: other
      Platform: Other

      Description

      I've got Log4J 1.1.3 JAR in my classpath. Upon startup of my application
      (actually a JUnit test case), I immediately get:

      java.lang.ExceptionInInitializerError:
      org.apache.commons.logging.LogConfigurationException:
      java.lang.ClassCastException

      So I downloaded the Commons Logging 1.0 source and debugged. The problem is in
      org.apache.commons.logging.impl.LogFactoryImpl.guessConfig().

      Class proxyClass=findClassLoader().
      loadClass( "org.apache.commons.logging.Log4jFactory" );

      The above loadClass call should be changed to:

      Class proxyClass=findClassLoader().
      loadClass( "org.apache.commons.logging.impl.Log4jFactory" );

      However, after I make the above change I still get a ClassCastException, now
      from org.apache.commons.logging.LogFactory.newFactory(). This exception
      baffles me. It happens at:

      return (LogFactory) clazz.newInstance();

      So I modify newFactory() to do the newInstance() and the return in two steps
      instead of one.

      Object result = clazz.newInstance();
      return (LogFactory)result;

      The exception occurs during the cast of result. If I print result's class name
      I get org.apache.commons.logging.impl.LogFactoryImpl. But checking if result
      is an instanceof org.apache.commons.logging.impl.LogFactoryImpl returns false.

      Object result = clazz.newInstance();
      System.out.println("Got Factory: " + result.getClass().getName());

      if (result instanceof LogFactory)

      { System.out.println("result is a LogFactory"); }

      if (result instanceof org.apache.commons.logging.impl.LogFactoryImpl)

      { System.out.println("result is a LogFactoryImpl"); }

      return (LogFactory) result;

      The code above just prints:
      Got Factory: org.apache.commons.logging.impl.LogFactoryImpl

      And then throws the ClassCastException. I'm confused.

        Activity

        Dennis Lundberg made changes -
        Fix Version/s 1.0.3 [ 12311839 ]
        Henri Yandell made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Dennis Lundberg made changes -
        Resolution Fixed [ 1 ]
        Status Reopened [ 4 ] Resolved [ 5 ]
        Dennis Lundberg made changes -
        Status Closed [ 6 ] Reopened [ 4 ]
        Dennis Lundberg made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Henri Yandell made changes -
        Affects Version/s 1.0 Final [ 12311814 ]
        Henri Yandell made changes -
        Project Commons [ 12310458 ] Commons Logging [ 12310484 ]
        Component/s Logging [ 12311124 ]
        Key COM-92 LOGGING-45
        Affects Version/s 1.0 Final [ 12311651 ]
        Assignee Jakarta Commons Developers Mailing List [ commons-dev@jakarta.apache.org ]
        Henri Yandell made changes -
        Field Original Value New Value
        issue.field.bugzillaimportkey 9845 12340243
        Jerome Jacobsen created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Jerome Jacobsen
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development