Bug 47547 - NullPointerException when calling Category.removeAllAppenders()
NullPointerException when calling Category.removeAllAppenders()
Status: RESOLVED FIXED
Product: Log4j
Classification: Unclassified
Component: Appender
1.2
All All
: P2 normal
: ---
Assigned To: log4j-dev
: PatchAvailable
Depends on:
Blocks:
  Show dependency tree
 
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.