Bug 47547 - NullPointerException when calling Category.removeAllAppenders()
Summary: NullPointerException when calling Category.removeAllAppenders()
Status: RESOLVED FIXED
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Appender (show other bugs)
Version: 1.2
Hardware: All All
: P2 normal
Target Milestone: ---
Assignee: log4j-dev
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2009-07-20 00:00 UTC by Michael
Modified: 2009-10-10 19:39 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael 2009-07-20 00:00:34 UTC
The Category.removeAllAppenders() fails, sometime, because of a wrong for-loop condition, and it throws a NullPointerException

The first for-loop in the Category.removeAllAppenders() looks as following:

for (Enumeration iter = aai.getAllAppenders(); iter.hasMoreElements();) {
          appenders.add(iter.nextElement());
}


But in one of my scenario (BTW I can't understand why it happened only to me), I got a null 'iter' variable, since the aai.getAllAppenders() may return 'null'.

So the right for-loop should be:

for (Enumeration iter = aai.getAllAppenders(); iter != null && iter.hasMoreElements();) {
          appenders.add(iter.nextElement());
}


Michael.
Comment 1 Curt Arnold 2009-10-10 19:39:37 UTC
Fix committed in rev 824000.

There were several checks for getAllAppenders() returning null, just not in removeAllAppenders.