sylvainlaurent / JDBC-Performance-Logger

A JDBC driver wrapper and GUI to analyze statement performance
Apache License 2.0
84 stars 26 forks source link

Can not set static ch.sla.jdbcperflogger.agent.DriverInterceptor field #58

Closed bardware closed 7 years ago

bardware commented 7 years ago

Hi,

I wanted to add perf-logger-agent to my Adobe Coldfusion install. I added the -javaagent switch to the startup arguments and got the error byte-buddy is missing. I added byte-buddy to a path I believe is part of the Classpath but kept getting the error. I eventually copied logger-agent, byte-buddy and logger-driver to the same folder. The Coldfusion service started up but was not usable. I found an exception in one of the log files:

"Error","localhost-startStop-1","05/07/17","14:18:22","","Unable to initialise License service: java.lang.ExceptionInInitializerError"
java.lang.ExceptionInInitializerError
    at coldfusion.license.LicenseServiceImpl.new(Unknown Source)
    at coldfusion.license.LicenseServiceImpl.init(Unknown Source)
    at coldfusion.license.LicenseServiceImpl.load(Unknown Source)
    at coldfusion.server.ServiceBase.start(ServiceBase.java:59)
    at coldfusion.server.CFService.setupLicense(CFService.java:427)
    at coldfusion.server.CFService.start(CFService.java:546)
    at coldfusion.server.j2ee.CFStartUpServlet.startCFService(CFStartUpServlet.java:565)
    at coldfusion.server.j2ee.CFStartUpServlet.init(CFStartUpServlet.java:508)
    at javax.servlet.GenericServlet.init(GenericServlet.java:158)
    at coldfusion.bootstrap.ClassloaderHelper.initServletClass(ClassloaderHelper.java:121)
    at coldfusion.bootstrap.BootstrapServlet.init(BootstrapServlet.java:59)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1183)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1099)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:989)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4965)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5275)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at macromedia.jdbc.MacromediaDriver.<clinit>(Unknown Source)
    ... 23 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at ch.sla.jdbcperflogger.agent.net.bytebuddy.agent.builder.Nexus.initialize(Nexus.java:95)
    ... 28 more
Caused by: java.lang.IllegalStateException: cannot assign runtime type class ch.sla.jdbcperflogger.agent.DriverInterceptor (sun.misc.Launcher$AppClassLoader@18b4aac2) to class ch.sla.jdbcperflogger.agent.DriverInterceptor (coldfusion.bootstrap.BootstrapClassLoader@f5ac09b)
    at ch.sla.jdbcperflogger.agent.net.bytebuddy.implementation.LoadedTypeInitializer$ForStaticField.onLoad(LoadedTypeInitializer.java:110)
    at ch.sla.jdbcperflogger.agent.net.bytebuddy.implementation.LoadedTypeInitializer$Compound.onLoad(LoadedTypeInitializer.java:186)
    at ch.sla.jdbcperflogger.agent.net.bytebuddy.agent.builder.AgentBuilder$InitializationStrategy$SelfInjection$Dispatcher$InjectingInitializer.onLoad(AgentBuilder.java:1768)
    ... 33 more
Caused by: java.lang.IllegalArgumentException: Can not set static ch.sla.jdbcperflogger.agent.DriverInterceptor field macromedia.jdbc.MacromediaDriver.delegate$289533742 to ch.sla.jdbcperflogger.agent.DriverInterceptor
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
    at sun.reflect.UnsafeStaticObjectFieldAccessorImpl.set(UnsafeStaticObjectFieldAccessorImpl.java:79)
    at java.lang.reflect.Field.set(Field.java:764)
    at ch.sla.jdbcperflogger.agent.net.bytebuddy.implementation.LoadedTypeInitializer$ForStaticField.onLoad(LoadedTypeInitializer.java:106)
    ... 35 more

The bottom most exception is an incompatibility between your class and the Macromedia JDBC driver. Is there a possibility to understand why it does not work or to do anything to make it work?

sylvainlaurent commented 7 years ago

I think you mixed things with the classpath, the bootstrap classpath and several jars... Normally you only need to add -javaagent:path/to/jdbc-perf-logger-agent-x.y.z.jar to your JVM arguments and that's it. Nothing to add in the classpath. If that's not the case, please provide the stacktrace of the error.

In the above stack trace, I see this:

Caused by: java.lang.IllegalStateException: cannot assign runtime type class ch.sla.jdbcperflogger.agent.DriverInterceptor (sun.misc.Launcher$AppClassLoader@18b4aac2) to class ch.sla.jdbcperflogger.agent.DriverInterceptor (coldfusion.bootstrap.BootstrapClassLoader@f5ac09b)

which reveals that the class ch.sla.jdbcperflogger.agent.DriverInterceptor has been loaded twice : once by the BootstratpClassLoader, once by the system classloader (sun.misc.Launcher$AppClassLoader), which is not correct. I guess you must have placed some jars in specific directories or you passed specific arguments to the JVM...

bardware commented 7 years ago

The information the jar was loaded twice helped alot. I moved it from a directory that is part of the classpath do a different folder. Now it in fact works without further confgurations. Thank you!