fix(agent): Append runtime JAR to bootstrap class loader#315
Merged
dividedmind merged 3 commits intodevelopfrom Jan 19, 2026
Merged
fix(agent): Append runtime JAR to bootstrap class loader#315dividedmind merged 3 commits intodevelopfrom
dividedmind merged 3 commits intodevelopfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes NoClassDefFoundError issues for HookFunctions in servlet containers like Tomcat by changing the AppMap runtime JAR to be appended to the bootstrap class loader instead of the system class loader. This ensures core AppMap runtime classes are available to all application classes regardless of their class loader.
Changes:
- Modified
Agent.javato useappendToBootstrapClassLoaderSearchinstead ofappendToSystemClassLoaderSearch - Added comprehensive gretty-tomcat integration test to verify the fix in a Tomcat servlet environment
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| agent/src/main/java/com/appland/appmap/Agent.java | Changed runtime JAR loading from system class loader to bootstrap class loader and updated explanatory comments |
| agent/test/gretty-tomcat/build.gradle | Gradle build configuration for the Tomcat test using Gretty plugin with servlet container and AppMap agent setup |
| agent/test/gretty-tomcat/src/main/java/org/example/HelloServlet.java | Simple servlet implementation to test basic request handling in Tomcat |
| agent/test/gretty-tomcat/src/main/java/org/example/MyClass.java | Test class with generic type parameters in the instrumented package |
| agent/test/gretty-tomcat/gretty-tomcat.bats | BATS test script that starts Tomcat server and verifies servlet responds correctly |
| agent/test/gretty-tomcat/appmap.yml | AppMap configuration specifying the org.example package for instrumentation |
| agent/test/gretty-tomcat/settings.gradle | Gradle settings file defining the project name |
| agent/test/gretty-tomcat/src/main/webapp/.keep | Placeholder file to preserve the webapp directory structure in version control |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
agent/test/gretty-tomcat/src/main/java/org/example/MyClass.java
Outdated
Show resolved
Hide resolved
agent/test/gretty-tomcat/src/main/java/org/example/MyClass.java
Outdated
Show resolved
Hide resolved
The AppMap runtime JAR must be appended to the bootstrap class loader search path. This ensures that core AppMap runtime classes, such as `HookFunctions`, are available to all application classes, regardless of the specific class loader (e.g., in web servers like Tomcat). This change fixes `NoClassDefFoundError` issues for `HookFunctions`. This commit also adds a new `gretty-tomcat` test to verify the fix in a servlet environment.
b9b4531 to
1558b7d
Compare
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The AppMap runtime JAR must be appended to the bootstrap class loader search path. This ensures that core AppMap runtime classes, such as
HookFunctions, are available to all application classes, regardless of the specific class loader (e.g., in web servers like Tomcat). This change fixesNoClassDefFoundErrorissues forHookFunctions.This commit also adds a new
gretty-tomcattest to verify the fix in a servlet environment.Another commit adds the ability to run with the whole agent JAR included in the bootstrap classpath in addition to the javaagent. This configuration is not recommended or exactly supported, but a user has found it helpful in working around some quirks in a specific complex classloader environment.