mirror of https://github.com/qos-ch/slf4j
SLF4J-324: lazy initializaiton of ClassContextSecurityManager in o.s.helpers.Util
This commit is contained in:
parent
37229d8d62
commit
46a49f4303
|
|
@ -67,8 +67,21 @@ public final class Util {
|
|||
}
|
||||
}
|
||||
|
||||
private static final ClassContextSecurityManager SECURITY_MANAGER = safeCreateSecurityManager();
|
||||
|
||||
private static ClassContextSecurityManager SECURITY_MANAGER;
|
||||
private static boolean SECURITY_MANAGER_CREATION_ALREADY_ATTEMPTED = false;
|
||||
|
||||
private static ClassContextSecurityManager getSecurityManager() {
|
||||
if(SECURITY_MANAGER != null)
|
||||
return SECURITY_MANAGER;
|
||||
else if(SECURITY_MANAGER_CREATION_ALREADY_ATTEMPTED)
|
||||
return null;
|
||||
else {
|
||||
SECURITY_MANAGER = safeCreateSecurityManager();
|
||||
SECURITY_MANAGER_CREATION_ALREADY_ATTEMPTED = true;
|
||||
return SECURITY_MANAGER;
|
||||
}
|
||||
}
|
||||
|
||||
private static ClassContextSecurityManager safeCreateSecurityManager() {
|
||||
try {
|
||||
return new ClassContextSecurityManager();
|
||||
|
|
@ -83,9 +96,10 @@ public final class Util {
|
|||
* @return the name of the class which called the invoking method.
|
||||
*/
|
||||
public static Class<?> getCallingClass() {
|
||||
if(SECURITY_MANAGER == null)
|
||||
ClassContextSecurityManager securityManager = getSecurityManager();
|
||||
if(securityManager == null)
|
||||
return null;
|
||||
Class<?>[] trace = SECURITY_MANAGER.getClassContext();
|
||||
Class<?>[] trace = securityManager.getClassContext();
|
||||
String thisClassName = Util.class.getName();
|
||||
|
||||
// Advance until Util is found
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ public class DetectLoggerNameMismatchTest {
|
|||
public void testTriggerWithProperty() {
|
||||
setTrialEnabled(true);
|
||||
LoggerFactory.getLogger(String.class);
|
||||
String s = String.valueOf(byteArrayOutputStream);
|
||||
assertMismatchDetected(true);
|
||||
}
|
||||
|
||||
|
|
@ -90,8 +91,9 @@ public class DetectLoggerNameMismatchTest {
|
|||
public void testTriggerWholeMessage() {
|
||||
setTrialEnabled(true);
|
||||
LoggerFactory.getLogger(String.class);
|
||||
assertTrue("Actual value of byteArrayOutputStream: " + String.valueOf(byteArrayOutputStream), String.valueOf(byteArrayOutputStream).contains(
|
||||
"Detected logger name mismatch. Given name: \"java.lang.String\"; " + "computed name: \"org.slf4j.DetectLoggerNameMismatchTest\"."));
|
||||
boolean success = String.valueOf(byteArrayOutputStream).contains(
|
||||
"Detected logger name mismatch. Given name: \"java.lang.String\"; " + "computed name: \"org.slf4j.DetectLoggerNameMismatchTest\".");
|
||||
assertTrue("Actual value of byteArrayOutputStream: " + String.valueOf(byteArrayOutputStream), success);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -29,7 +29,15 @@
|
|||
|
||||
<hr noshade="noshade" size="1"/>
|
||||
|
||||
<h3>, 2015 - Release of SLF4J 1.7.13</h3>
|
||||
<h3>10th of November, 2015 - Release of SLF4J 1.7.13</h3>
|
||||
|
||||
|
||||
<p>Fixed <code>LoggerFactory</code> initialisation problem in
|
||||
presence of SecurityManager denying "createSecurityManage"r
|
||||
RuntimePermission. See <a
|
||||
href="http://jira.qos.ch/browse/SLF4J-324">SLF4J-324</a> for
|
||||
further details.
|
||||
</p>
|
||||
|
||||
<p>Fixed issue with <code>BasicMDCAdapter</code> leaking MDC
|
||||
information to non-child threads. This problem was reported by
|
||||
|
|
|
|||
Loading…
Reference in New Issue