diff --git a/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/symbol/JarScanner.java b/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/symbol/JarScanner.java index 028335685b5..ea3c48a73a4 100644 --- a/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/symbol/JarScanner.java +++ b/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/symbol/JarScanner.java @@ -12,6 +12,7 @@ public class JarScanner { private static final Logger LOGGER = LoggerFactory.getLogger(JarScanner.class); private static final String JAR_FILE_PREFIX = "jar:file:"; + private static final String JAR_NESTED_PREFIX = "jar:nested:"; private static final String FILE_PREFIX = "file:"; // Spring prefixes: // https://docs.spring.io/spring-boot/docs/current/reference/html/executable-jar.html @@ -41,6 +42,11 @@ public static Path extractJarPath(ProtectionDomain protectionDomain) throws URIS if (idx != -1) { return getPathFromPrefixedFileName(locationStr, JAR_FILE_PREFIX, idx); } + } else if (locationStr.startsWith(JAR_NESTED_PREFIX)) { + int idx = locationStr.indexOf("/!BOOT-INF/"); + if (idx != -1) { + return getPathFromPrefixedFileName(locationStr, JAR_NESTED_PREFIX, idx); + } } else if (locationStr.startsWith(FILE_PREFIX)) { return getPathFromPrefixedFileName(locationStr, FILE_PREFIX, locationStr.length()); } diff --git a/dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/symbol/JarScannerTest.java b/dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/symbol/JarScannerTest.java index 2e31dbfca76..8d2136adcd2 100644 --- a/dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/symbol/JarScannerTest.java +++ b/dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/symbol/JarScannerTest.java @@ -1,11 +1,16 @@ package com.datadog.debugger.symbol; import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; import java.net.URLClassLoader; +import java.security.CodeSource; +import java.security.ProtectionDomain; +import java.security.cert.Certificate; import org.junit.jupiter.api.Test; class JarScannerTest { @@ -31,4 +36,15 @@ public void extractJarPathFromFile() throws ClassNotFoundException, URISyntaxExc Class testClass = urlClassLoader.loadClass(CLASS_NAME); assertEquals(jarFileUrl.getFile(), JarScanner.extractJarPath(testClass).toString()); } + + @Test + public void extractJarPathFromNestedJar() throws URISyntaxException { + URL jarFileUrl = getClass().getResource("/debugger-symbol.jar"); + URL mockLocation = mock(URL.class); + when(mockLocation.toString()) + .thenReturn("jar:nested:" + jarFileUrl.getFile() + "/!BOOT-INF/classes/!"); + CodeSource codeSource = new CodeSource(mockLocation, (Certificate[]) null); + ProtectionDomain protectionDomain = new ProtectionDomain(codeSource, null); + assertEquals(jarFileUrl.getFile(), JarScanner.extractJarPath(protectionDomain).toString()); + } }