appender can't be added to AsyncAppender after being detached.
2. reproduce and test case
add following test in AsyncAppenderBaseTest
@Test
@Timeout(value=2, unit = TimeUnit.SECONDS)
public void appenderShouldBeAddedSuccessfullyAfterDetachedByReference() {
asyncAppenderBase.addAppender(listAppender);
asyncAppenderBase.start();
asyncAppenderBase.doAppend(0);
asyncAppenderBase.detachAppender(listAppender);
asyncAppenderBase.addAppender(listAppender);
asyncAppenderBase.doAppend(0);
asyncAppenderBase.stop();
verify(listAppender, 2);
}
3. cause
the value of property "appenderCount" does't decrease in method "detachAppender", the value is 1 after first addAppender, and still 1 after detachAppender, so when addAppender again, it goes into "else".
public void addAppender(Appender<E> newAppender) {
if (appenderCount == 0) {
appenderCount++;
addInfo("Attaching appender named [" + newAppender.getName() + "] to AsyncAppender.");
aai.addAppender(newAppender);
} else {
addWarn("One and only one appender may be attached to AsyncAppender.");
addWarn("Ignoring additional appender named [" + newAppender.getName() + "]");
}
}
1. behavior
appender can't be added to AsyncAppender after being detached.
2. reproduce and test case
add following test in AsyncAppenderBaseTest
3. cause
the value of property "appenderCount" does't decrease in method "detachAppender", the value is 1 after first addAppender, and still 1 after detachAppender, so when addAppender again, it goes into "else".