Skip to content

Commit

Permalink
split URL classloader from best-match classloader attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Oct 25, 2024
1 parent ffd0929 commit dad8eb0
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/main/java/io/cryostat/agent/ConfigModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import javax.inject.Named;
import javax.inject.Singleton;

import io.cryostat.agent.util.ResourcesUtil;
import io.cryostat.agent.util.StringUtils;

import dagger.Module;
Expand Down Expand Up @@ -220,25 +221,26 @@ public static Config provideConfig() {
fns.add(Pair.of("Simple", ConfigProvider::getConfig));
fns.add(
Pair.of(
"Current Thread Context Classloader",
"ResourcesUtil Classloader",
() -> {
// if we don't do this then the SmallRye Config loader may end up with a
// null classloader in the case that the Agent starts separately and is
// dynamically attached to a running VM, which results in an NPE. Here
// we try to detect and preempt that case and ensure that there is a
// reasonable classloader for the SmallRye config loader to use.
PrivilegedExceptionAction<ClassLoader> pea =
() -> {
ClassLoader cl =
Thread.currentThread().getContextClassLoader();
if (cl != null) {
return cl;
}
return new URLClassLoader(
new URL[] {Agent.selfJarLocation().toURL()});
};
ClassLoader cl = AccessController.doPrivileged(pea);
return ConfigProvider.getConfig(cl);
ResourcesUtil::getClassLoader;
return ConfigProvider.getConfig(AccessController.doPrivileged(pea));
}));
fns.add(
Pair.of(
"Agent JAR URL Classloader",
() -> {
PrivilegedExceptionAction<ClassLoader> pea =
() ->
new URLClassLoader(
new URL[] {Agent.selfJarLocation().toURL()});
return ConfigProvider.getConfig(AccessController.doPrivileged(pea));
}));
fns.add(
Pair.of(
Expand Down

0 comments on commit dad8eb0

Please sign in to comment.