-
-
Notifications
You must be signed in to change notification settings - Fork 808
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
NoClassDefFound -- new class cannot access the class whose classloader was used for injection #419
Comments
The NoClassDefFoundError might be misleading and point to an error in your instrumentation. It could be a erification error in disguise. Are you instrumenting your code using Byte Buddy? I am wondering why you do not operate on a dynamic type. I would need to see more of your example to provide better help. I think the actual problem is in the byte code generation. |
Looks like you were right about the problem's lying with the code generation. Couldn't post more code because it's proprietary and frankly, too darn large. Didn't help that all the "minimal working examples" I tried to construct actually worked ... The issue turned out to be disappointingly trivial: a string constant used dots instead of slashes to separate package names. Since that constant is used by ASM and looking for Yeah, really stupid. As for why I'm not using a dynamic type, it's that we already have ASM visitors that do part of the transformation required for the new class. The bytebuddy tutorial, however, says
and quite frankly, that's too much of a hassle (and in my case actually bars me from using the ASM visitors we already have because they rely on the fact that stack frames are computed). It's much more convenient to write something like
and let ASM figure out the rest. |
You can still use ASM with Byte Buddy in this case, have a look at AsmVisitorWrapper.ForDeclaredMethods. you can register frame computation in there and still use ASM for the method body. Glad you figured it out. |
In that case, may I suggest adding this information to the tutorial? Because I read "ByteBuddy will not" as "ByteBuddy refuses to" and stopped considering ByteBuddy for transformations right then and there. |
Yes, please! Could you do a PR on the gh-pages branch with a suggestion? |
Can do, but it will take a while. |
No worries, if I find time first, I will do it, otherwise, I can easily just merge your PR. |
In a nutshell, I have a class
B$1
that I create from scatch at runtime and that has a non-static method calling a static method of classB$0
(there is no inheritance between the two classes, although they may share the parent, but even that's not a necessity).Injection is done by
but if I immediately after that injection test the method
I get a
NoClassDefFoundError: B$0
.Why? And how do I resolve this?
(For more details about the use case, please see https://stackoverflow.com/questions/49232664/how-to-load-this-class-in-the-correct-way .)
Oh, and if at all relevant: using Java 1.7.0_65 and ByteBuddy 1.7.9
The text was updated successfully, but these errors were encountered: