defineClass(className, byte[], offset, length)
.new CustomClassLoader(Thread.currentThread().getContextClassLoader())
.
So the parent of my CustomClassLoader is the ClassLoader from the current thread.Thread.currentThread().setContextClassLoader()
with my CustomClassLoader.Class.forName(String, true, the CustomClassLoader)
.What did I wrong ? If you need more info, a detailed topic is on my GitHub.
Java classloaders first search the parent classloader before looking in the child.
The loadClass method in ClassLoader performs these tasks, in order, when called to load a class:
- If a class has already been loaded, it returns it.
- Otherwise, it delegates the search for the new class to the parent class loader.
- If the parent class loader does not find the class, loadClass calls the method findClass to find and load the class.
(Understanding Extension Class Loading - Oracle)
If you want to change that order, you need to override the loadClass
method as well but there are many caveats and it's not advisable unless you understand classloading very well.
B
.