Class not found exception LogginAdvice
See original GitHub issueHi, I am loading an Advice Class using URLClassLoader, but the app is throwing a ClassNotFound Exception exception wheneve I am using a class variable inside the function.
Agent :
Class<?> testClass=null;;
try {
testClass = Class.forName("com.exp.LoggingAdvice", true, classLoader);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Class = "+testClass.getCanonicalName());
return new AgentBuilder.Default().disableClassFormatChanges()
.with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
.with(AgentBuilder.RedefinitionStrategy.REDEFINITION)
.with(AgentBuilder.TypeStrategy.Default.REDEFINE)
.type(ElementMatchers.hasSuperType(named(className)))
.transform(new AgentBuilder.Transformer.ForAdvice()
.include(classLoader)
.advice(named(methodName), testClass.getName())
);
Output:
`Class = com.exp.LoggingAdvice
2019-07-25 13:10:41.932 INFO 17674 — [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet ‘dispatcherServlet’ 2019-07-25 13:10:41.933 INFO 17674 — [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet ‘dispatcherServlet’ 2019-07-25 13:10:42.036 INFO 17674 — [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 102 ms LOL 2019-07-25 13:10:42.147 ERROR 17674 — [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: com.exp.LoggingAdvice`
In the output, check
LOL
It is present in the same ClassFile(LoggingAdvice), but wherever there is a First class variable in the function, it throws ClassNotFoundException.
Can anyone Help ? I am a beginner at this bytecode manipulation and unfortunately, to classloading concept aswell.
Issue Analytics
- State:
- Created 4 years ago
- Comments:19 (9 by maintainers)

Top Related StackOverflow Question
For debugging, please consider to add
AgentBuilder.Listener.StreamWriting.toSystemOut()in your build configuration. It will show you your agent’s activity.Glad you figured it out.
Bytebuddy is able to instrument java.sql.Statement without pushing the agent into the Bootstrap Loader. In my case what I wanted to check is, whenever a call is made from my java application to a mysql DB, I wanted my agent to trace it.
For that, I tried to instrument java.sql.Statement, but was facing some issues. So I added SystemOut listener and found out that Bytebuddy was not able to find my Advice class :
java.lang.IllegalStateException: Cannot resolve type description for com.exp.innerloader.DBTracingI am using an agentLoader which loads my main agent in a CustomClassLoader. So I added my advice files to the agentLoader, which in turn, loaded the advice class in SystemClassLoader and then, my agent was easily able to find the Advice class.