Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Nov 4, 2024
1 parent f1da161 commit 5b65288
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/main/java/io/cryostat/agent/ConfigModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,30 +239,32 @@ public static Config provideConfig() {
fns.add(
Pair.of(
"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 =
ResourcesUtil::getClassLoader;
return ConfigProvider.getConfig(AccessController.doPrivileged(pea));
}));
() ->
ConfigProvider.getConfig(
AccessController.doPrivileged(
(PrivilegedExceptionAction<ClassLoader>)
ResourcesUtil::getClassLoader))));
fns.add(
Pair.of(
"Agent JAR URL Classloader",
() -> {
PrivilegedExceptionAction<ClassLoader> pea =
() ->
new URLClassLoader(
new URL[] {Agent.selfJarLocation().toURL()});
return ConfigProvider.getConfig(AccessController.doPrivileged(pea));
}));
"Config Class Classloader",
() ->
ConfigProvider.getConfig(
AccessController.doPrivileged(
(PrivilegedExceptionAction<ClassLoader>)
Config.class::getClassLoader))));
fns.add(
Pair.of(
"Config Class Classloader",
() -> ConfigProvider.getConfig(Config.class.getClassLoader())));
"Agent JAR URL Classloader",
() ->
ConfigProvider.getConfig(
AccessController.doPrivileged(
(PrivilegedExceptionAction<ClassLoader>)
() ->
new URLClassLoader(
new URL[] {
Agent.selfJarLocation()
.toURL()
})))));

Config config = null;
for (Pair<String, Callable<Config>> fn : fns) {
Expand Down

0 comments on commit 5b65288

Please sign in to comment.