Skip to content

Synchronize Category.aai access in log4j-1.2-api (#4512) - #4525

Open
vitor-correia wants to merge 1 commit into
apache:2.xfrom
vitor-correia:fix/4512-category-aai-sync
Open

vitor-correia wants to merge 1 commit into
apache:2.xfrom
vitor-correia:fix/4512-category-aai-sync

Conversation

@vitor-correia

Copy link
Copy Markdown

Fixes #4512

In log4j-1.2-api, Category.addAppender() and Category.callAppenders() guard access to Category.aai with synchronized (this) / synchronized (c), while removeAllAppenders(), removeAppender(...), isAttached(...), getAllAppenders(), and getAppender(...) accessed aai without synchronization. Concurrent calls to removeAllAppenders() could null out aai while another thread had already passed a null check, causing a NullPointerException.

This PR synchronizes all remaining aai reads and writes in Category on this (keeping fireRemoveAppenderEvent outside the synchronized block, matching addAppender's fireAddAppenderEvent), adds concurrency unit tests in CategoryConcurrencyTest, and includes a changelog entry under src/changelog/.2.x.x/.

Checklist

  • Base your changes on 2.x branch if you are targeting Log4j 2; use main otherwise
  • ./mvnw spotless:apply test spotbugs:check -pl log4j-1.2-api -am succeeds
  • Non-trivial changes contain an entry file in the src/changelog/.2.x.x directory
  • Tests are provided

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

[1.2 bridge] callAppenders can throw NPE when removeAllAppenders runs concurrently

1 participant