Skip to content

Commit eb7ea9e

Browse files
steveraootelbot[bot]trask
authored
Add constructor to AgentClassLoader for custom parent ClassLoader (#14480)
Co-authored-by: otelbot <[email protected]> Co-authored-by: Trask Stalnaker <[email protected]>
1 parent d2a267a commit eb7ea9e

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/AgentClassLoader.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,27 @@ public AgentClassLoader(File javaagentFile) {
8484
*/
8585
public AgentClassLoader(
8686
File javaagentFile, String internalJarFileName, boolean isSecurityManagerSupportEnabled) {
87-
super(new URL[] {}, getParentClassLoader());
87+
this(javaagentFile, internalJarFileName, isSecurityManagerSupportEnabled, null);
88+
}
89+
90+
/**
91+
* Construct a new AgentClassLoader with a custom parent ClassLoader. This is used by some 3rd
92+
* party command-line utilities in order to reuse classes that are bundled as classdata files
93+
* under `inst/`.
94+
*
95+
* @param javaagentFile Used for resource lookups.
96+
* @param internalJarFileName File name of the internal jar
97+
* @param isSecurityManagerSupportEnabled Whether this class loader should define classes with all
98+
* permissions
99+
* @param parentClassLoader Custom parent ClassLoader to use. If null, the default parent will be
100+
* used.
101+
*/
102+
public AgentClassLoader(
103+
File javaagentFile,
104+
String internalJarFileName,
105+
boolean isSecurityManagerSupportEnabled,
106+
@Nullable ClassLoader parentClassLoader) {
107+
super(new URL[] {}, parentClassLoader != null ? parentClassLoader : getParentClassLoader());
88108
if (javaagentFile == null) {
89109
throw new IllegalArgumentException("Agent jar location should be set");
90110
}

0 commit comments

Comments
 (0)