Skip to content

A way to disable the optimization for filling the stack traces #3638

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,35 @@ final class PrivateSecurityManagerStackTraceUtil {
private static final PrivateSecurityManager SECURITY_MANAGER;

static {
PrivateSecurityManager candidate = createPrivateSecurityManager();
if (isCapable(candidate)) {
SECURITY_MANAGER = candidate;
} else {
SECURITY_MANAGER = null;
}
}

private static boolean isCapable(PrivateSecurityManager candidate) {
if (candidate == null) {
return false;
}

try {
final Class<?>[] result = candidate.getClassContext();
if (result == null || result.length == 0) {
// This happens e.g. on Android which has real implementation of SecurityManager replaced with merely
// stubs. So the PrivateSecurityManager, though can be instantiated, will not produce meaningful
// results
return false;
}
// Add more checks here as needed
return true;
} catch (Exception ignored) {
return false;
}
}

private static PrivateSecurityManager createPrivateSecurityManager() {
PrivateSecurityManager psm;
try {
final SecurityManager sm = System.getSecurityManager();
Expand All @@ -40,7 +69,7 @@ final class PrivateSecurityManagerStackTraceUtil {
psm = null;
}

SECURITY_MANAGER = psm;
return psm;
}

private PrivateSecurityManagerStackTraceUtil() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://logging.apache.org/xml/ns"
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
type="fixed">
<issue id="3639" link="https://github.com/apache/logging-log4j2/issues/3639"/>
<description format="asciidoc">
Verify the capability of SecurityManager so that platforms not (fully) supporting it will not poison the stack trace
</description>
</entry>