Skip to content

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

Open

Description

@ashitpatel

Description

In the log4j-1.2 bridge, Category.callAppenders reads aai under synchronized (c):

synchronized (c) {
    if (c.aai != null) {
        writes += c.aai.appendLoopOnAppenders(event);
    }
    ...
}

but Category.removeAllAppenders is not synchronized: it iterates the appenders, calls aai.removeAllAppenders(), fires remove events, and only then sets aai = null. If another thread's callAppenders passes the null check in between, it dereferences the nulled aai and throws NullPointerException. The field is also not volatile, so the window is wider than the race itself.

Trigger: one thread logging through a 1.2-bridge Category in a loop while another thread calls removeAllAppenders() on it (e.g. a reconfiguration path). I have not executed this — reporting from code reading plus a model of the interleaving, so please treat the report with appropriate skepticism; a sketch of the reproducer is below.

Configuration

Version: 2.x branch HEAD (verified 2026-11-21)

Operating system: N/A (code reading; any OS)

JDK: N/A (any; would reproduce with e.g. OpenJDK 21+ and a two-thread JUnit test)

Logs

None (no execution; the NPE site is Category.java:249, c.aai.appendLoopOnAppenders(event) after aai is nulled at line 584).

Reproduction

Unrun sketch (two threads sharing one Category: one calling a logging method in a tight loop, one calling removeAllAppenders() repeatedly; expect intermittent NPE from callAppenders). I can turn this into a real JUnit test in the repo's style if the diagnosis looks right — just say the word.

Possible direction: synchronize removeAllAppenders (and ideally removeAppender, same shape) on the Category, matching callAppenders.

Activity

  1. added
    appenders
    bug
    priority: P2
    on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    appendersbuglegacy-1.2-bridgepriority: P2waiting-for-maintainer

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions