NoClassDefFound -- new class cannot access the class whose classloader was used for injection
@raphw is already working on this.
Since Mar 15, 2018.
- Dominant language
- Java
- Stars
- 6.9k
- Forks
- 855
- PR merge metrics
- No merged PRs in 30d
Description
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 class B$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
Class b0 = Class.forName("B$0");
ClassLoadingStrategy.Default.INJECTION.load(b0.getClassLoader(),
Collections.singletonMap(newClass.getTypeDescription(), finishedBytecode));
but if I immediately after that injection test the method
try {
Class c = Class.forName("B$1");
Object instance = c.newInstance();
c.getMethod("move", Object.class).invoke(instance, new Object());
} catch (Exception e) {
e.printStackTrace();
}
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.