Skip to content
Closed
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
2 changes: 1 addition & 1 deletion CHANGELOG.next-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This file contains all changes which are not released yet.

# Fixes
<!--FIXES-START-->

- Fix JVM tool bootstrap check when program arguments contain slashes - [#4269](https://github.com/elastic/apm-agent-java/issues/4269)
<!--FIXES-END-->
# Features and enhancements
<!--ENHANCEMENTS-START-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,20 @@ public static void checkJdkTool(String jvmCmd, BootstrapCheckResult result) {
return;
}

// only the main class or module part is relevant, program arguments may contain slashes
String mainClass = parts.length > 0 ? parts[0] : jvmCmd;

boolean isJdkTool = false;

parts = jvmCmd.split("/");
parts = mainClass.split("/");
if (parts.length == 2) {
// JDK with module system
isJdkTool = parts[0].startsWith("jdk.") || parts[0].startsWith("java.");
} else if (parts.length == 1) {
isJdkTool = jvmCmd.startsWith("sun.") || jvmCmd.startsWith("com.sun.") || jvmCmd.startsWith("jdk.");
// com.sun.enterprise.* is the GlassFish/Payara bootstrap, an application server rather than a JDK tool
isJdkTool = mainClass.startsWith("sun.") ||
(mainClass.startsWith("com.sun.") && !mainClass.startsWith("com.sun.enterprise.")) ||
mainClass.startsWith("jdk.");
} else {
result.addWarn("Unexpected JVM command line syntax: " + jvmCmd);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class JvmToolBootstrapCheckTest {
"sun.tools.jstat.Jstat",
"sun.tools.native2ascii.Main",
"sun.tools.serialver.SerialVer",
// with program arguments containing slashes
"java.base/sun.security.tools.keytool.Main -list -keystore /tmp/keystore.jks",
"sun.security.tools.keytool.Main -list -keystore /tmp/keystore.jks",
})
void testJdkTool(String cmd) {
BootstrapCheck.BootstrapCheckResult result = new BootstrapCheck.BootstrapCheckResult();
Expand All @@ -115,6 +118,9 @@ void checkNotJdkTool() {
checkNotJdkTool("/target/app.jar"); // java -jar /target/app.jar
checkNotJdkTool("/target/app.jar with some arguments"); // java -jar /target/app.jar with arguments
checkNotJdkTool("app.Main"); // java app.Main
checkNotJdkTool("org.example.Main --file /my/path/containing/slashes/file.txt"); // java org.example.Main --file /my/path/...
checkNotJdkTool("my.module/org.example.Main --file /my/path/file.txt"); // java -m my.module/org.example.Main --file /my/path/file.txt
checkNotJdkTool("com.sun.enterprise.glassfish.bootstrap.ASMain -upgrade false -domaindir /opt/payara/glassfish/domains/domain1"); // Payara
checkNotJdkTool(System.getProperty("sun.java.command")); // Maven/IDE JUnit runner
}

Expand Down
Loading