wood burning stoves*
The moose likes Java in General and the fly likes What need to implement SystemClassLoader? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "What need to implement SystemClassLoader?" Watch "What need to implement SystemClassLoader?" New topic
Author

What need to implement SystemClassLoader?

Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
OK, first - I apologize for posting a ton of questions, but i really do need the answers to all of them. And when I get the answers I always post it back to the board (usually with example source code) Now on to the question...
I know that I have to set "java.system.class.loader" which I've already done. But when I use my classloader (just extends URLClassLoader), it loads a bunch of classes, loads my class, hits the static part of my classloader, loads a few more classes then throws this:
Error occurred during initialization of VM
java.lang.Error: java.lang.NullPointerException
Does anyone know what might be causing this? What do i need to do to make my classloader the system classloader?
1 more question: if a class simply does: Blah b = new Blah(); is that class' classloader the system classloader?
Thanks!
Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
I had to correctly implement loadClass. Does anyone have a really good tutorial/examination of implementing the ClassLoader (completely, not just extending URLClassLoader)?
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
My reply is still a bit vague, but please read on. I've read your other question about the recursion problem when doing security checks. Every class loader extends from the abstract class ClassLoader and every class loader delegates certain amounts of work (especially the mysterious defineClass method) to their 'parent' class loader. Note that this 'parent' class loader had nothing to do with the parent class of the class loader we're talking about.
Of course your class loader delegates some work to its parent class loader. Are you sure that you don't simply delegate work to the, say, super.defineClass() methods (in your particular case, this super class happens to be the URLClassLoader class)? If so, these super methods may call their 'parent' class loader again and this 'parent' class loader happens to be your classloader again, because you've forced it to be the system (or 'bootstrap') class loader. And there's the recursion problem rearing its ugly head ...
Does this vague reply make sense to you?
kind regards
Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
except there was no recursion in my classloader, that was in my policy object. And that recursion happened even when I used the built in classloader (sun.misc.Launcher$AppClassLoader).
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Ok, forget my previous reply, I was thinking in the wrong direction, I apologize. There's one small thing that still bothers me though:
I had to correctly implement loadClass. Does anyone have a really good tutorial/examination of implementing the ClassLoader (completely, not just extending URLClassLoader)?
I don't understand this, because the default implementation takes care of the entire logic in a templetized way (i.e. you fill in the nasty details, like findClass(), while loadClass() takes care of the control flow).
kind regards
Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
Oh, it's like this: I wanted to keep classes invisible to each other so in the load class, I check the threadgroup it comes from and I have a collection of URLClassLoaders that I use to store the classes for each ThreadGroup, so I pass it on to the proper one of those. So yes, I do delegate, but not to the parent loader.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: What need to implement SystemClassLoader?