Skip to content

Allow disabling the optimization for filling the stack traces #3639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
neboskreb opened this issue Apr 25, 2025 · 3 comments
Open

Allow disabling the optimization for filling the stack traces #3639

neboskreb opened this issue Apr 25, 2025 · 3 comments
Labels
android bug Incorrect, unexpected, or unintended behavior of existing code waiting-for-maintainer

Comments

@neboskreb
Copy link
Contributor

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

@ppkarwasz
Copy link
Contributor

ppkarwasz commented Apr 25, 2025

@neboskreb,

Thank you for the report.

PS: In the website for the upcoming 2.25.0 release we added a FAQ entry about Android. Can you add a reference to your Log4j API implementation and explain how it differs from com.celeral:log4j2-android?

@neboskreb
Copy link
Contributor Author

Can you add a reference to your Log4j API implementation and explain how it differs from com.celeral:log4j2-android?

Sure, will do ASAP!

@neboskreb
Copy link
Contributor Author

@ppkarwasz

Added a small section. See #3643

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android bug Incorrect, unexpected, or unintended behavior of existing code waiting-for-maintainer
Projects
Status: Ready
Development

No branches or pull requests

2 participants