Bug 45231 - Clear appenders call on logger calls a helper which calls close on the appenders
Summary: Clear appenders call on logger calls a helper which calls close on the appenders
Status: ASSIGNED
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Appender (show other bugs)
Version: 1.2
Hardware: PC Windows XP
: P2 normal
Target Milestone: ---
Assignee: log4j-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-18 17:10 UTC by David Berkman
Modified: 2009-01-08 09:09 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Berkman 2008-06-18 17:10:55 UTC
Clear appenders call on logger calls a helper which calls close on the appenders, even though appenders are shared objects and may still be active in other loggers, or re-used later. You can't assume that removal equates to a desire to close.
Comment 1 Thorbjørn Ravn Andersen 2008-07-03 13:37:24 UTC
Please attach a testcase demonstrating the behaviour you are reporting.
Comment 2 David Berkman 2008-07-03 14:32:48 UTC
(In reply to comment #1)
> Please attach a testcase demonstrating the behaviour you are reporting.
> 

You've got to be kidding. It's directly in your code. Here's the stack trace...

	at org.apache.log4j.helpers.AppenderAttachableImpl.removeAllAppenders(AppenderAttachableImpl.java:141)
at org.apache.log4j.Category.removeAllAppenders(Category.java:891)

Calling Category.removeAllAppenders() results in a call to AppenderAttachableImpl.removeAllAppenders(), probably because this is set as the default listener for the remove event internally. Looking at the code fro the removeAllAppenders method in AppenderAttachableImpl, we see...

  public
  void removeAllAppenders() {
    if(appenderList != null) {
      int len = appenderList.size();      
      for(int i = 0; i < len; i++) {
	Appender a = (Appender) appenderList.elementAt(i);
	a.close();
      }
      appenderList.removeAllElements();
      appenderList = null;      
    }
  }

Look at that a.close(). Why is this method calling close on an Appender simply because it has been removed from a logger? Appenders are shared objects. I wonder how the other loggers that Appender is attached to will feel about it being closed underneath them? What happens when I re-use this Appender?

In my opinion this is incorrect behavior.
Comment 3 Thorbjørn Ravn Andersen 2008-07-03 16:47:35 UTC
(In reply to comment #2)
 
> You've got to be kidding. It's directly in your code. Here's the stack trace...

I am not kidding, and it is not my code (you can see that in the Subversion history).  By providing a testcase it can be demonstrated that the bug exists, and that the patch removed the bug.  Otherwise we can only guess what caused the bug and if the handwaving code introduced fixed it in the way you expected.

Hence, please provide a testcase.

> In my opinion this is incorrect behavior.

Most likely. 
Comment 4 Curt Arnold 2009-01-08 09:09:50 UTC
There is enough info to address the bug, so I'm dropping the NEEDINFO designation.

The behavior described is undesirable but long established.  I don't think that removing the "a.close()" would be acceptable since some app might depend on removeAllAppenders() closing the appenders.  However, I could see only closing the appenders that are not otherwise attached, however detecting that might be complicated.