Bug 5444

Summary: AsyncAppender throws NullPointerException
Product: Log4j - Now in Jira Reporter: Tory Stephen Toupin <ttoupin>
Component: AppenderAssignee: log4j-dev <log4j-dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P3    
Version: 1.1   
Target Milestone: ---   
Hardware: All   
OS: All   

Description Tory Stephen Toupin 2001-12-15 15:14:36 UTC
 
Comment 1 Tory Stephen Toupin 2001-12-15 15:19:41 UTC
When AsyncAppender is closed, it will generate a NullPointerException on 
subsequent appends.  Refer to bug 509 for a similar bug.

Suggest patch:

Index: AsyncAppender.java
===================================================================
RCS file: /home/cvspublic/jakarta-
log4j/src/java/org/apache/log4j/AsyncAppender.java,v
retrieving revision 1.24
diff -u -r1.24 AsyncAppender.java
--- AsyncAppender.java  2001/11/17 01:04:21     1.24
+++ AsyncAppender.java  2001/12/15 23:19:05
@@ -104,6 +104,10 @@

   public
   void append(LoggingEvent event) {
+    if (bf == null) {
+       LogLog.warn("AsyncAppender closed.");
+       return;
+    }
     // Set the NDC and thread name for the calling thread as these
     // LoggingEvent fields were not set at event creation time.
     event.getNDC();
Comment 2 Ceki Gulcu 2002-05-09 16:32:40 UTC
Thanks for the bug report. This was a nasty bug because it was very hard to
catch.

In AppenderSkeleton, doAppend method was changed from

  public
  synchronized 
  void doAppend(LoggingEvent event) {
    if(closed) {
      LogLog.error("Attempted to append to closed appender named ["+name+"].");
    }
   ....

to

  public
  synchronized 
  void doAppend(LoggingEvent event) {
    if(closed) {
      LogLog.error("Attempted to append to closed appender named ["+name+"].");
      return;
    }
   ...

The fix will be available in log4j 1.2 final.