Commons Logging
  1. Commons Logging
  2. LOGGING-58

[logging] null pointer exception in LogFactory.getLog

    Details

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

      Operating System: Mac OS X 10.3
      Platform: Macintosh

      Description

      In running the LoggingTrial example from the book "Pro Jakarta Commons" by Oak from Apress on
      MacOSX 10.3.7, java version "1.4.2_05-141.3", I get the following error:

      run_example:
      [java] Exception in thread "main" org.apache.commons.logging.LogConfigurationException:
      org.apache.commons.logging.LogConfigurationException: java.lang.NullPointerException (Caused by
      java.lang.NullPointerException) (Caused by org.apache.commons.logging.LogConfigurationException:
      java.lang.NullPointerException (Caused by java.lang.NullPointerException))
      [java] at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:543)
      [java] at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
      [java] at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
      [java] at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
      [java] at com.commonsbook.chap3.LoggingTrial.main(LoggingTrial.java:8)
      [java] Caused by: org.apache.commons.logging.LogConfigurationException:
      java.lang.NullPointerException (Caused by java.lang.NullPointerException)
      [java] at
      org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:397)
      [java] at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:529)
      [java] ... 4 more
      [java] Caused by: java.lang.NullPointerException
      [java] at
      org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:374)
      [java] ... 5 more

      Up to this point everything in the book worked. I doubt user error. MacOSX java implementation?

        Activity

        Donald Huebschman created issue -
        Hide
        Dennis Lundberg added a comment -

        I downloaded the example and tried it successfully on Windows XP with Java
        1.4.2_06. Note that my locale is set to sv_SE. Here is the output:

        The Log being used >>> org.apache.commons.logging.impl.Jdk14Logger@7c6768
        2005-jan-24 17:19:46 com.commonsbook.chap3.LoggingTrial main
        INFO: INFO TEST
        2005-jan-24 17:19:46 com.commonsbook.chap3.LoggingTrial main
        INFO: INFO TEST
        java.lang.Exception: A DUMMY EXCEPTION
        at com.commonsbook.chap3.LoggingTrial.main(LoggingTrial.java:14)
        2005-jan-24 17:19:46 com.commonsbook.chap3.LoggingTrial main
        VARNING: WARN TEST
        2005-jan-24 17:19:46 com.commonsbook.chap3.LoggingTrial main
        VARNING: WARN TEST
        java.lang.Exception: A DUMMY EXCEPTION
        at com.commonsbook.chap3.LoggingTrial.main(LoggingTrial.java:14)
        2005-jan-24 17:19:46 com.commonsbook.chap3.LoggingTrial main
        ALLVARLIG: ERROR TEST
        2005-jan-24 17:19:46 com.commonsbook.chap3.LoggingTrial main
        ALLVARLIG: ERROR TEST
        java.lang.Exception: A DUMMY EXCEPTION
        at com.commonsbook.chap3.LoggingTrial.main(LoggingTrial.java:14)
        2005-jan-24 17:19:46 com.commonsbook.chap3.LoggingTrial main
        ALLVARLIG: FATAL TEST
        2005-jan-24 17:19:46 com.commonsbook.chap3.LoggingTrial main
        ALLVARLIG: FATAL TEST
        java.lang.Exception: A DUMMY EXCEPTION
        at com.commonsbook.chap3.LoggingTrial.main(LoggingTrial.java:14)

        Show
        Dennis Lundberg added a comment - I downloaded the example and tried it successfully on Windows XP with Java 1.4.2_06. Note that my locale is set to sv_SE. Here is the output: The Log being used >>> org.apache.commons.logging.impl.Jdk14Logger@7c6768 2005-jan-24 17:19:46 com.commonsbook.chap3.LoggingTrial main INFO: INFO TEST 2005-jan-24 17:19:46 com.commonsbook.chap3.LoggingTrial main INFO: INFO TEST java.lang.Exception: A DUMMY EXCEPTION at com.commonsbook.chap3.LoggingTrial.main(LoggingTrial.java:14) 2005-jan-24 17:19:46 com.commonsbook.chap3.LoggingTrial main VARNING: WARN TEST 2005-jan-24 17:19:46 com.commonsbook.chap3.LoggingTrial main VARNING: WARN TEST java.lang.Exception: A DUMMY EXCEPTION at com.commonsbook.chap3.LoggingTrial.main(LoggingTrial.java:14) 2005-jan-24 17:19:46 com.commonsbook.chap3.LoggingTrial main ALLVARLIG: ERROR TEST 2005-jan-24 17:19:46 com.commonsbook.chap3.LoggingTrial main ALLVARLIG: ERROR TEST java.lang.Exception: A DUMMY EXCEPTION at com.commonsbook.chap3.LoggingTrial.main(LoggingTrial.java:14) 2005-jan-24 17:19:46 com.commonsbook.chap3.LoggingTrial main ALLVARLIG: FATAL TEST 2005-jan-24 17:19:46 com.commonsbook.chap3.LoggingTrial main ALLVARLIG: FATAL TEST java.lang.Exception: A DUMMY EXCEPTION at com.commonsbook.chap3.LoggingTrial.main(LoggingTrial.java:14)
        Hide
        Richard A. Sitze added a comment -

        LogFactoryImpl.java:543

        541: if (logMethod != null)

        { 542: params[0] = this; 543: logMethod.invoke(instance, params); 544: }

        So... not sure what version of the code you're using, but looks to me like
        your line#543 can't be the same as the most recent source. This isn't a
        recent code change either.

        Please pull a recent build, retry, and supply us with a stack-trace that
        matches current code. Thanks.

        Show
        Richard A. Sitze added a comment - LogFactoryImpl.java:543 541: if (logMethod != null) { 542: params[0] = this; 543: logMethod.invoke(instance, params); 544: } So... not sure what version of the code you're using, but looks to me like your line#543 can't be the same as the most recent source. This isn't a recent code change either. Please pull a recent build, retry, and supply us with a stack-trace that matches current code. Thanks.
        Hide
        Richard A. Sitze added a comment -

        Oh wait.. this is a reflective invoke. How fun. Strike that last note.

        Show
        Richard A. Sitze added a comment - Oh wait.. this is a reflective invoke. How fun. Strike that last note.
        Hide
        Richard A. Sitze added a comment -

        I would still like to ensure that you are running this with a recent nightly
        build, to ensure line #'s line up. Also, if there is any more detail on the
        stacktrace, I'd like to see that... it looks like we're losing the interesting
        detail on the core problem.

        Show
        Richard A. Sitze added a comment - I would still like to ensure that you are running this with a recent nightly build, to ensure line #'s line up. Also, if there is any more detail on the stacktrace, I'd like to see that... it looks like we're losing the interesting detail on the core problem.
        Hide
        Donald Huebschman added a comment -

        I am using 1.0.4 version which I believe is the most recent. I have the commons-logging in the java
        endorsed directory as well as in a separate classpath listed lib directory. Removing it from classpath
        doesn't change anything, have not removed it from endorsed.

        Show
        Donald Huebschman added a comment - I am using 1.0.4 version which I believe is the most recent. I have the commons-logging in the java endorsed directory as well as in a separate classpath listed lib directory. Removing it from classpath doesn't change anything, have not removed it from endorsed.
        Hide
        Donald Huebschman added a comment -

        I removed commons-logging from endorsed and left it in classpath. It now works as it suppose to,
        except, it defaults to log4j and not simplelog.

        Something I don't understand happens when commons-logging is in the java/lib/endorsed directory.

        Show
        Donald Huebschman added a comment - I removed commons-logging from endorsed and left it in classpath. It now works as it suppose to, except, it defaults to log4j and not simplelog. Something I don't understand happens when commons-logging is in the java/lib/endorsed directory.
        Hide
        David Baker added a comment -

        Could this be because the docs for Class.getClassLoader() include:

        "Returns the class loader for the class. Some implementations may use null to represent the bootstrap
        class loader. This method will return null in such implementations if this class was loaded by the
        bootstrap class loader."

        If Apple's JRE does return null, and commons-logging is in the system classpath (/Library/Java/
        Extensions)...

        The relevant snippet from 1.0.4 source (ultimate cause at LogFactoryImpl:374) is:

        logInterface = this.getClass().getClassLoader().loadClass
        (LOG_INTERFACE);

        If getClassLoader() indeed returns null, as the API spec allows?...

        Show
        David Baker added a comment - Could this be because the docs for Class.getClassLoader() include: "Returns the class loader for the class. Some implementations may use null to represent the bootstrap class loader. This method will return null in such implementations if this class was loaded by the bootstrap class loader." If Apple's JRE does return null, and commons-logging is in the system classpath (/Library/Java/ Extensions)... The relevant snippet from 1.0.4 source (ultimate cause at LogFactoryImpl:374) is: logInterface = this.getClass().getClassLoader().loadClass (LOG_INTERFACE); If getClassLoader() indeed returns null, as the API spec allows?...
        Hide
        rdonkin@apache.org added a comment -

        The code which seems to be in question now reads:

        ClassLoader cl = this.getClass().getClassLoader();
        // handle the case if getClassLoader() returns null
        // It may mean this class was loaded from the bootstrap classloader
        logInterface = (cl == null) ? loadClass(LOG_INTERFACE) :
        cl.loadClass(LOG_INTERFACE);
        logClass = loadClass(logClassName);

        This looks ok.

        I've tried to replicate on my PowerBook with the newest code but doesn't seem to
        happen any more.

        Show
        rdonkin@apache.org added a comment - The code which seems to be in question now reads: ClassLoader cl = this.getClass().getClassLoader(); // handle the case if getClassLoader() returns null // It may mean this class was loaded from the bootstrap classloader logInterface = (cl == null) ? loadClass(LOG_INTERFACE) : cl.loadClass(LOG_INTERFACE); logClass = loadClass(logClassName); This looks ok. I've tried to replicate on my PowerBook with the newest code but doesn't seem to happen any more.
        Hide
        Dennis Lundberg added a comment -

        This was fixed by the patch for issue 31710.

        Show
        Dennis Lundberg added a comment - This was fixed by the patch for issue 31710.
        Henri Yandell made changes -
        Field Original Value New Value
        issue.field.bugzillaimportkey 33221 12342013
        Henri Yandell made changes -
        Affects Version/s 1.0.4 [ 12311678 ]
        Component/s Logging [ 12311124 ]
        Key COM-1861 LOGGING-58
        Assignee Jakarta Commons Developers Mailing List [ commons-dev@jakarta.apache.org ]
        Project Commons [ 12310458 ] Commons Logging [ 12310484 ]
        Henri Yandell made changes -
        Affects Version/s 1.0.4 [ 12311713 ]
        Henri Yandell made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Dennis Lundberg made changes -
        Fix Version/s 1.1.0 [ 12311848 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Donald Huebschman
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development