Irit Katriel
Irit Katriel

Reputation: 3564

Java Instrumentation/JavassistHelper example code does not work

I am trying to build and run my own version of the example in this tutorial

I made an eclipse project that runs the HelloWorld class with instrumentation. If I use the loggeragent.jar I downloaded from the link at the bottom of that page, it works. But if I build loggeragent.jar (from the same source code), it throws an exception in method.insertBefore():

Could not instrument HelloWorld, exception : [source error] syntax error near "r($1)+"));"

The signature string that it tries to insert is, according to the debugger:

"main(" + "args" + "="+ org.slf4j.instrumentation.ToStringHelper.render($1)+")"

Now, I needed to make a few changes to some imports to get the code to build. In particular, I needed to add import org.slf4j.instrumentation.JavassistHelper;. So it could be that the two jars are not using the same version of JavaassistHelper, but I can't find another version.

Any idea why this doesn't work? Also, could you explain what JavaassistHelper does, or point me to a manual?

Upvotes: 2

Views: 332

Answers (1)

Irit Katriel
Irit Katriel

Reputation: 3564

I found out what the issue is - there is a error in the example code - it says

method.insertBefore(ifLog + "_log.info(\">> " + signature + ");");

Where it should say

method.insertBefore(ifLog + "_log.info(\">> " + signature + "\");");

(missing a \" towards the end).

Upvotes: 1

Related Questions