byte-buddy: Class not found exception LogginAdvice
Hi, 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.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 19 (9 by maintainers)
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.