Scala Classloader with java.lang.ClassLoader.registerAsParallelCapable

Currently i have a custom classloader which extends java.net.URLClassLoader#URLClassLoader, and i want to enable my custom classloader as parallel capable. To do this i need to call a static method from my custom classloader java.lang.ClassLoader#registerAsParallelCapable

In java custom classloader this would be as straightforward as having registration done in a static block, but currently i see that for scala i need to do this is a companion object and not in my custom class, but i doubt that will take affect as

  1. Internally this registration will register only Reflection.getCallerClass().
  2. Will companion object also have to extend URLClassLoader.? (no default constructor in URLClassLoader and cannot pass null as it will throw exception)

Any pointers.?

It will not take affect as inside java.lang.ClassLoader#registerAsParallelCapable the class name is registered via its name which is got by Reflection.getCallerClass() which will give companion class name abc.MyClassLoader$ instead of actual class abc.MyClassLoader thus failing to enforce parallel capability for classloader

I suspect you’ll have to work around with something like a delegating java classloader that just delegates to your logic in scala methods. As far as I know static initialization of classes doesn’t exist in Scala.