question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Class not found exception LogginAdvice

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
raphwcommented, Aug 21, 2019

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.

0reactions
Blaciascommented, Aug 21, 2019

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.DBTracing

I 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix ClassNotFoundException in Java - Rollbar
The Java ClassNotFoundException occurs when the JVM tries to load a class but does not find it in the classpath. Learn the three...
Read more >
How do I resolve ClassNotFoundException? - Stack Overflow
When you get a ClassNotFoundException, it means the JVM has traversed the entire classpath and not found the class you've attempted to reference....
Read more >
ClassNotFoundException vs NoClassDefFoundError - Baeldung
Both ClassNotFoundException and NoClassDefFoundError occur when the JVM can not find a requested class on the classpath.
Read more >
java.lang.ClassNotFoundException - DigitalOcean
Java ClassNotFoundException occurs when the application tries to load a class but Classloader is not able to find it in the classpath.
Read more >
ClassNotFoundException (Java Platform SE 8 )
public class ClassNotFoundException extends ReflectiveOperationException. Thrown when an application tries to load in a class through its string name using:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found