TravaOpenJDK / trava-jdk-11-dcevm

dcevm-11 built on Travis
Apache License 2.0
403 stars 57 forks source link

LinkageError when used with Tomcat #30

Closed achimmihca closed 3 years ago

achimmihca commented 3 years ago

I try to use the hot-swap feature on a multi-project Maven web app. We use Tomcat as Servlet Container.

When I do a Build > Rebuild in IntelliJ, it is telling me "142 classes reloaded" in a green notification bubble. So far so good. Yet, when I continue to use the webapp, I get the following Exception. (Note that I replaced actual class and file names with TheClass, TheReturnValueClass, and the_jspfile.jsp)

java.lang.LinkageError: loader constraint violation: when resolving method 'the.package.TheReturnValueClass the.package.TheClass.theStaticGetterMethod()' the class loader org.apache.jasper.servlet.JasperLoader @177e6b28 of the current class, org/apache/jsp/jspa/thejsppackage/the_005fjspfile_jsp, and the class loader org.apache.catalina.loader.ParallelWebappClassLoader @4583ad6d for the method's defining class, the/package/TheClass, have different Class objects for the type the/package/TheReturnValueClass used in the signature (org.apache.jsp.jspa.thejsppackage.the_005fjspfile_jsp is in unnamed module of loader org.apache.jasper.servlet.JasperLoader @177e6b28, parent loader org.apache.catalina.loader.ParallelWebappClassLoader @4583ad6d; the.package.TheClass is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @4583ad6d, parent loader java.net.URLClassLoader @76b07f29)
        at org.apache.jsp.jspa.thejsppackage.the_005fjspfile_jsp._jspService(the_005fjspfile_jsp.java:280)

Note that the code change that I wanted to hot-swap is neither in TheClass, nor in TheReturnValueClass nor in the JSP file. I guess the classes where the error occurs are among the 142 changed classes. Maybe they are updated but not all compiled JSP files use this new definition?

Note further that the TheClass and TheReturnValueClass are part of a lib project, not the main project. Maybe this is a reason why the class definition is not updated correctly? Maybe it is not updated everywhere (in a JAR built from another project)?

JVM Version I use the newest release of hotswapagent, namely Dcevm-11.0.9+1 (2020-11-24) In IntelliJ I configured additional VM-argument for Tomcat "-XX:HotswapAgent=fatjar".

Tomcat Plugin My logs show

HOTSWAP AGENT: 15:40:54.886 INFO (org.hotswap.agent.config.PluginRegistry) - Discovered plugins: [JdkPlugin, Hotswapper, WatchResources, ClassInitPlugin, AnonymousClassPatch, Hibernate, Hibernate3JPA, Hibernate3, Spring, Jersey1, Jersey2, Jetty, Tomcat, ZK, Logback, Log4j2, MyFaces, Mojarra, Omnifaces, ELResolver, WildFlyELResolver, OsgiEquinox, Owb, Proxy, WebObjects, Weld, JBossModules, ResteasyRegistry, Deltaspike, GlassFish, Vaadin, Wicket, CxfJAXRS, FreeMarker, Undertow, MyBatis]

So I guess the DECVM is started and I am also using Tomcat plugin.

hotswap-agent.properties

I have a hotswap-agent.properties file where I added the compiled output location of classes from my plugins. Consider my project structure to be like

theproject | - libproject | - mainproject

I have

# hotswap-agent.properties
extraClasspath=\
  D:\\repos\\theproject\\mainproject\\..\\libproject\\target\\classes;\
  D:\\repos\\theproject\\mainproject\\target\\classes;

Note that the path is a little weird because I am using a Maven property, i.e., ${project.basedir}\\..\\libproject\\target\\classes;\ and ${project.basedir} points to mainproject. Are relative paths allowed in extraClasspath? How can I check that hotswap-agent.properties is working as intended?

Conclusion

Am I missing some config, is it a bug, or is it a limitation of the DECVM hot-swap features?

skybber commented 3 years ago

Hi, it is definitely HotswapAgent issue. I'm not expert on JSP loading, but we had several issues with JSP in the past. There are some related threads on google groups https://groups.google.com/g/hotswapagent/search?q=JasperLoader. Could you please create a new issue in HotswapAgent (look if there is some similar) and write your finding there?