On Thu, Sep 16, 2010 at 9:22 AM, Jevgeni Kabanov <[email protected]> wrote:
> Bob, if you check the link to the blog post, it described such an > implementation that I did a while ago. > Doh! Sorry for not reading that. > Unfortunately what I found out is that it doesn't work with some class > loaders. Mainly because there are class loaders that at some point in their > life cycle will throw an exception when a loadClass() is issued, and even if > you use defineClass() a loadClass() is still issued for java.lang.Object > when defining your class for the first time, causing an exception. So in the > end I'm not using that code either, but I would be using it if it was safe. > Ugh. That's unfortunate. You could submit a patch to OpenJDK. Patching ClassLoader on the fly sounds like a better idea though; it'd take years before you'd be able to use a patch. You could patch all ClassLoader subclasses instead. That would be easier to do on the fly than patching ClassLoader itself. You'd instrument loadClass() so that if you're loading ClassLoaderLocals, it would run your loadClass() code (which would retrieve classes in the system classloader) instead of the original code which would otherwise throw an exception. Bob
