Skip to content

Broken logger initialization in 2.24.1 #3143

Closed
@kelunik

Description

@kelunik

Description

LoggerContext / LoggerRegistry don't play well together in using weak references, which can result in a null logger if the GC kicks in at a bad timing.

Configuration

Version: 2.24.1

Operating system: Linux / macOS

JDK: 21.0.4

Logs

java.lang.NullPointerException

Cannot invoke "org.apache.logging.log4j.spi.ExtendedLogger.logIfEnabled(String, org.apache.logging.log4j.Level, org.apache.logging.log4j.Marker, String)" because "this.logger" is null

at org.apache.logging.slf4j.Log4jLogger.warn(Log4jLogger.java:233)
at <internal company code>

Reproduction

Optimizing transformations of a program can be designed that reduce the number of objects that are reachable to be less than those which would naively be considered reachable. For example, a Java compiler or code generator may choose to set a variable or parameter that will no longer be used to null to cause the storage for such an object to be potentially reclaimable sooner.

https://docs.oracle.com/javase/specs/jls/se21/html/jls-12.html#jls-12.6.1

Fix

#2936 should fix this, but is currently unreleased.

Reference.reachabilityFence would also fix this, but is JDK 9+ only.

See also: https://shipilev.net/jvm/anatomy-quarks/8-local-var-reachability/

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiAffects the public APIbugIncorrect, unexpected, or unintended behavior of existing code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions