Bug 5444 - AsyncAppender throws NullPointerException
AsyncAppender throws NullPointerException
Status: RESOLVED FIXED
Product: Log4j
Classification: Unclassified
Component: Appender
1.1
All All
: P3 normal
: ---
Assigned To: log4j-dev
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2001-12-15 15:14 UTC by Tory Stephen Toupin
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.