logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 11570] New: - XML Appender throws NullPointerException when logging null
Date Thu, 08 Aug 2002 20:24:31 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=11570>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=11570

XML Appender throws NullPointerException when logging null

           Summary: XML Appender throws NullPointerException when logging
                    null
           Product: Log4j
           Version: 1.2
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: Critical
          Priority: Other
         Component: Appender
        AssignedTo: log4j-dev@jakarta.apache.org
        ReportedBy: dvandegrift@bluearc.com


Overview Description:

When calling log.error(null), a NullPointerException is thrown.  See the stack
trace below.

Of course, I wasn't calling log.error(null) in my code.  Rather, I was logging
an exception message as such:  
   log.error(e.getMessage())  <-- triggered exception
But the exception message was null so log4j threw an NullPointerException.

Steps to Reproduce:
1. Setup the following XML Appender section in your log4j.properties file.
######## XML SECTION ##################
# XML is a RollingFileAppender 
#######################################
log4j.appender.XML=org.apache.log4j.RollingFileAppender
log4j.appender.XML.file=${base-path}logs/mgr_log.xml
log4j.appender.XML.MaxFileSize=20MB
log4j.appender.XML.MaxBackupIndex=5
log4j.appender.XML.layout=org.apache.log4j.xml.XMLLayout
log4j.appender.XML.append=true

2. Create a class with the following line:
   log.error(null)

3. Or use the following try/catch block
   try {
       throw new Exception();
   }
   catch (Exception e) {
       log.error(e, e);              // works as expected
       log.error("bug found", e);    // works as expected
       log.error(e.getMessage());    // throws NullPointerException
       log.error(e.getMessage(), e); // throws NullPointerException
   }


Actual Results:
A NullPointerException is thrown as represented in the following stack trace:

######### Stack Trace ###############
java.lang.NullPointerException
 at org.apache.log4j.helpers.Transform.appendEscapingCDATA(Transform.java:74)
 at org.apache.log4j.xml.XMLLayout.format(Unknown Source)
 at org.apache.log4j.WriterAppender.subAppend(WriterAppender.java:292)
 at org.apache.log4j.RollingFileAppender.subAppend(RollingFileAppender.java:225)
 at org.apache.log4j.WriterAppender.append(WriterAppender.java:150)
 at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:221)
at
org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:57)
 at org.apache.log4j.Category.callAppenders(Category.java:187)
 at org.apache.log4j.Category.forcedLog(Category.java:372)
 at org.apache.log4j.Category.error(Category.java:286)
 at com.bluearc.mgr.screens.Index.doThroughput(Index.java:253)


Expected Results:
An XML formatted message should have been logged to mgr_log.xml with an empty
CDATA section.  Similar to:
<log4j:message>![CDATA[]]</log4j:message>
or
<log4j:message></log4j:message>


Build & Platform:
build: Log4j version 1.2.5 (release ver)
platform: RedHat 7.2 & Windows 2000 with JDK 1.3.1_02


Additional Builds and Platforms:
 - Occurs On
        Log4j version 1.2.6


Additional Information:
 - xerces1_4_4.jar and xalan-j_2_4_D1.jar in classpath.

--
To unsubscribe, e-mail:   <mailto:log4j-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:log4j-dev-help@jakarta.apache.org>


Mime
View raw message