Skip to content

Commit 126fd47

Browse files
committed
Fix potential timing issue involving CustomLogManagerTest
Avoid accessing the CustomLogManager type in the LogManagerSetter test application because this will load jul.LogManager, which triggers our class-loading hooks, and ends up activating various Tracer services like JMX that initialize JUL. If this happens before we've set the custom logger system property, ie: System.setProperty("java.util.logging.manager", CustomLogManager.class.getName()); then there's a very small window where JUL could be initialized before the updated system property has taken effect (since the class-loading hook and follow-on services run on a different thread.)
1 parent ec1aabd commit 126fd47

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

dd-java-agent/src/test/java/jvmbootstraptest/LogManagerSetter.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
import java.util.logging.LogManager;
55

66
public class LogManagerSetter {
7+
8+
// avoid CustomLogManager.class.getName() as that could initialize JUL before we've set the logger
9+
private static final String CUSTOM_LOG_MANAGER_CLASS_NAME = "jvmbootstraptest.CustomLogManager";
10+
711
public static void main(final String... args) throws Exception {
812
if (System.getProperty("dd.app.customlogmanager") != null) {
913
System.out.println("dd.app.customlogmanager != null");
1014

1115
if (Boolean.valueOf(System.getProperty("dd.app.customlogmanager"))) {
12-
System.setProperty("java.util.logging.manager", CustomLogManager.class.getName());
16+
System.setProperty("java.util.logging.manager", CUSTOM_LOG_MANAGER_CLASS_NAME);
1317
customAssert(
1418
LogManager.getLogManager().getClass(),
1519
LogManagerSetter.class
@@ -49,7 +53,7 @@ public static void main(final String... args) throws Exception {
4953
"profiling startup must be delayed when log manager system property is present.");
5054
}
5155
// Change back to a valid LogManager.
52-
System.setProperty("java.util.logging.manager", CustomLogManager.class.getName());
56+
System.setProperty("java.util.logging.manager", CUSTOM_LOG_MANAGER_CLASS_NAME);
5357
customAssert(
5458
LogManager.getLogManager().getClass(),
5559
LogManagerSetter.class
@@ -93,7 +97,7 @@ public static void main(final String... args) throws Exception {
9397
"profiling startup must be delayed when JBOSS_HOME property is present.");
9498
}
9599

96-
System.setProperty("java.util.logging.manager", CustomLogManager.class.getName());
100+
System.setProperty("java.util.logging.manager", CUSTOM_LOG_MANAGER_CLASS_NAME);
97101
customAssert(
98102
LogManager.getLogManager().getClass(),
99103
LogManagerSetter.class

0 commit comments

Comments
 (0)