Skip to content

Allow disabling the optimization for filling the stack traces #3639

Closed
@neboskreb

Description

@neboskreb

Allow disabling the optimization for filling the stack traces

Description

Utility PrivateSecurityManagerStackTraceUtil offers an optimized way to fill the stack traces. For this it uses SecurityManager.getClassContext() which is faster.

Unfortunately, it is not always possible. On Android security managers are not used. Though class SecurityManager is present in the classpath, it contains just stubs; hence the array returned from getClassContext() is always null.
This results in an NPE when Log4J tries to use it to fill the stack trace.


Fortunately, Log4J library will first check isEnabled() before using this optimization.

Configuration

Version: 2.24.3

Operating system: Android

JDK: not relevant

Logs

Not relevant

Reproduction

Just log an arbitrary exception:

log.warn("test", new Exception());

Solution

For now, the proposed remedy is to allow the developer on Android to explicitly disable this optimization.

A bigger problem is coming later, as java.lang.SecurityManager is deprecated and marked for removal. Once it is removed, the PrivateSecurityManagerStackTraceUtil (who internally extends SecurityManager) will start failing to load on Android. That will require a better mechanism to exclude this optimization from the execution path.

Action points

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions