feat(agent): Support running agent on bootstrap classpath#316
feat(agent): Support running agent on bootstrap classpath#316dividedmind wants to merge 1 commit intodevelopfrom
Conversation
- Update `Agent.java` to use `Agent.class.getResource()` instead of `Agent.class.getClassLoader().getResource()` when locating the agent JAR. This prevents a `NullPointerException` when the agent is loaded by the bootstrap class loader (where `getClassLoader()` returns null). - Modify `Properties.java` to automatically default `appmap.debug.disableGit` to `true` if the agent is running on the bootstrap classpath. This avoids crashes in JGit initialization, which relies on `ResourceBundle` loading that is problematic in the bootstrap context. - Add a warning log in `Agent.premain` when running on the bootstrap classpath, advising that this configuration is for troubleshooting only.
There was a problem hiding this comment.
Pull request overview
This PR adds support for running the AppMap Java agent on the bootstrap classpath, which is an unsupported configuration intended for troubleshooting purposes only. The changes prevent NullPointerException errors that occur when the agent is loaded by the bootstrap class loader.
Changes:
- Modified
Agent.javato handle null class loader by usingClass.getResource()instead ofClassLoader.getResource() - Updated
Properties.javato automatically disable Git integration when running on bootstrap classpath to avoid JGit initialization crashes - Added comprehensive test coverage for the bootstrap classpath configuration
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| agent/src/main/java/com/appland/appmap/Agent.java | Fixed NullPointerException by using Class.getResource() and added warning log for bootstrap classpath usage |
| agent/src/main/java/com/appland/appmap/config/Properties.java | Auto-disable Git integration when agent runs on bootstrap classpath |
| agent/test/classloading/classloading.bats | Added test case for bootstrap classpath configuration |
| agent/test/classloading/app/src/main/java/com/appland/appmap/test/fixture/TestBootstrapClasspath.java | Added test implementation to verify bootstrap classpath functionality |
| agent/test/classloading/app/build.gradle | Added conditional logic to support testing with bootstrap classpath |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /*"-Dsun.misc.URLClassPath.debug",*/ | ||
| "-DtestJars=${configurations.servlet.asPath};${libJar}", | ||
| "-Djava.util.logging.config.file=${System.env.JUL_CONFIG}" | ||
| "-javaagent:${appmapJar}", |
There was a problem hiding this comment.
When useBootstrapClasspath is true, the -javaagent argument should not be included in the JVM arguments since the agent is being loaded via -Xbootclasspath/a instead. Both options being present simultaneously could lead to the agent being loaded twice or other unexpected behavior. The -javaagent argument should be conditionally added only when not using the bootstrap classpath.
|
Merged into #315 which is actually a prerequisite. |
Note this is not an officially supported or recommended configuration, but a user found this useful in troubleshooting and working around some issues with complicated classloader.
Agent.javato useAgent.class.getResource()instead ofAgent.class.getClassLoader().getResource()when locating the agent JAR. This prevents aNullPointerExceptionwhen the agent is loaded by the bootstrap class loader (wheregetClassLoader()returns null).Properties.javato automatically defaultappmap.debug.disableGittotrueif the agent is running on the bootstrap classpath. This avoids crashes in JGit initialization, which relies onResourceBundleloading that is problematic in the bootstrap context.Agent.premainwhen running on the bootstrap classpath, advising that this configuration is for troubleshooting only.