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

Runtime Exception: Class not found on Tomcat with classes with static methods when tracing is active #45

Open
MarcelTUC opened this issue Oct 6, 2016 · 0 comments

Comments

@MarcelTUC
Copy link

My environement is a tomcat running a book shop. This shop has a class "Database" inter alia containing 2 static methods. Method 1: "getBook" calls another static method "getConnection", that returns a database connection. After instrumenting getBook via AIM, a runtime exception is thrown on the next call to getBook when the trace should also be instrumented. That says, that the class "Database" cannot be found.

Why this happens?
When AIM instruments the method "getBook", the "Database" class is loaded by the class loader of Tomcat. After instrumenting "getBook", AIM wants to instrument the trace, the methods called from "getBook". Here is the exception thrown because, the trace instrumentation wants to load the class from the boot class loader of Tomcat, but the "Database" class isn't there anymore.

Hotfix?
We found out that we can hotfix this problem. We need to say, that the javassist.runtime.Desc class should load the class not by default from the boot class loader but from the context class loader, that is in this case the WebappClassLoader of Tomcat.

As hotfix we insert some code here:

org.aim.mainagent.instrumentation.FullTraceMethodEditor.edit(...) {
  Desc.useContextClassLoader = true;
  try { 
    ...
  } ...
}

This line of code directs the class loader to load the classes from the thread and not from the boot class loader.

Future work:
We think, that it would be useful to do this by default in the use cases of AIM.
So this setting should done eventually on initializing the Mainagent instead of every time the trace gots instrumented.

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

No branches or pull requests

1 participant