Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvocationTargetException in Gradle Gretty project #635

Open
haba713 opened this issue Jan 23, 2025 · 1 comment
Open

InvocationTargetException in Gradle Gretty project #635

haba713 opened this issue Jan 23, 2025 · 1 comment

Comments

@haba713
Copy link

haba713 commented Jan 23, 2025

The issue

HotswapAgent causes InvocationTargetException in a Gradle Gretty project.

  • servletContainer = 'jetty11'ERROR (org.hotswap.agent.annotation.handler.PluginClassFileTransformer) - InvocationTargetException in transform method on plugin 'class org.hotswap.agent.plugin.jetty.JettyPlugin' class 'org/eclipse/jetty/webapp/WebXmlConfiguration' of classLoader 'java.net.URLClassLoader'
  • servletContainer = 'tomcat10'ERROR (org.hotswap.agent.annotation.handler.PluginClassFileTransformer) - InvocationTargetException in transform method on plugin 'class org.hotswap.agent.plugin.tomcat.TomcatPlugin' class 'org/apache/catalina/webresources/StandardRoot' of classLoader 'java.net.URLClassLoader'

Details

See the details here.

Environment

$ hotswapagent-gretty-issue/gradlew -v

------------------------------------------------------------
Gradle 8.12
------------------------------------------------------------

Build time:    2024-12-20 15:46:53 UTC
Revision:      a3cacb207fec727859be9354c1937da2e59004c1

Kotlin:        2.0.21
Groovy:        3.0.22
Ant:           Apache Ant(TM) version 1.10.15 compiled on August 25 2024
Launcher JVM:  17.0.12 (JetBrains s.r.o. 17.0.12+1-b1087.25)
Daemon JVM:    /Users/u0/.sdkman/candidates/java/17.0.12-jbr (no JDK specified, using current Java home)
OS:            Mac OS X 14.7.2 aarch64
@skybber
Copy link
Contributor

skybber commented Jan 26, 2025

Thanks for the excellent example. It seems that the transformation of WebXmlConfiguration fails because it relies on Thread.currentThread().getContextClassLoader(), which is set to UrlClassLoader. This class loader cannot see the app class loader of the HA. The Java agent is initialized by default in the AppClassLoader. I tried enforcing initialization in the bootstrap loader:

gretty {
    httpPort = 8080
    contextPath = '/'
    servletContainer = 'jetty11' // 'tomcat10'
    jvmArgs = [
        '-XX:+AllowEnhancedClassRedefinition',
        '-javaagent:<path-to-hotswap-agent>/hotswap-agent.jar',
        '-Xbootclasspath/a:<path-to-hotswap-agent>/hotswap-agent.jar'
    ]
}

This resolves the first issue, but another one arises. It looks like a deeper investigation will be required. Unfortunately, I don’t know much about Gretty and don’t have enough time to explore it in depth. However, I can provide advice if you decide to dive into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants