[Bluej-discuss] CheckStyle extension
Davin McCall
davmac at bluej.org
Mon Oct 9 04:11:53 BST 2006
Stephen Edwards wrote:
> Universally in the checkstyle code base, everything uses
> Thread.currentThread().getContextClassLoader() to look up
> the appropriate class loader.
Hmm, my feeling is that this is the wrong thing to do. It should be
expected that resources bundled as part of a library should be loadable
by the same classloader as loaded the libraries classes, so surely it
makes much more sense to use that same classloader. It's not guaranteed
that the context classloader will be the same one. In fact it's fairly
unclear when the context classloader *is* supposed to be used, but one
good answer (for obvious reasons) is "when the current classloader
(which loaded the current class) may not actually find the resource I am
looking for". An example is RMI: the core RMI classes are generally
going to be loaded by the system classloader, whereas they need to be
able to find classes which are potentially loaded by a different
classloader.
So, this sounds to me like a bug in Checkstyle - it shouldn't be using
the context classloader. It should instead be doing
"this.getClass().getClassLoader()" (or "Self.class.getClassLoader()",
where "Self" is the name of the current class) to find an appropriate
classloader.
If anyone is interested, there's an article here with more discussion
about the use of current vs context class loaders:
http://www.javaworld.com/javaworld/javaqa/2003-06/01-qa-0606-load.html
Davin
More information about the bluej-discuss
mailing list