Skip to content

Commit 582d492

Browse files
committed
Java agent class path warning printed from Java 11
1 parent 94ce828 commit 582d492

File tree

1 file changed

+7
-0
lines changed
  • agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init

1 file changed

+7
-0
lines changed

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/FirstEntryPoint.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ public void init(EarlyInitAgentConfig earlyConfig) {
126126
// class path null with a Spring Boot executable JAR
127127
if (classPath != null
128128
// JAR name in Maven central, the user could have renamed it
129+
&& isJavaVersionEqualOrGreaterThan11() // -javaagent content added to the classpath in
130+
// Java 1.8
129131
&& classPath.contains("applicationinsights-agent")) {
130132
startupLogger.warn(
131133
"The applicationinsights-agent JAR is in the class path. You should remove it because it could lead to unexpected results. You should configure the Java agent with -javaagent. You can also use the runtime attachment with Spring Boot applications.");
@@ -151,6 +153,11 @@ public void init(EarlyInitAgentConfig earlyConfig) {
151153
}
152154
}
153155

156+
private static boolean isJavaVersionEqualOrGreaterThan11() {
157+
String javaVersion = System.getProperty("java.vm.specification.version");
158+
return !"1.8".equals(javaVersion) && !"9".equals(javaVersion) && !"10".equals(javaVersion);
159+
}
160+
154161
private static Map<String, String> findEnvVariables() {
155162
Map<String, String> env = System.getenv();
156163
return env.entrySet().stream()

0 commit comments

Comments
 (0)