[Bluej-discuss] CheckStyle extension
Ian Utting
I.A.Utting at kent.ac.uk
Fri Oct 6 22:05:14 BST 2006
Hi Steve -
> Universally in the checkstyle code base, everything uses
> Thread.currentThread().getContextClassLoader() to look up
> the appropriate class loader. It appears that for extensions,
> the classloader associated with the thread invoking extension
> methods is *not* the one that contains the classpath for the
> extension's classes. I ended up changing all references to
> use getClass().getClassLoader(). This means that, regardless
> of the class loader in effect for the current thread, the
> class loader used to load the checkstyle classes would be used
> to search for resources.
Ooh. Nice bug :-)
> For the extension mechanism, the question is really
> this: is there a useful reason (other than an accident of how the
> code was developed) for these two class loaders to be different?
Probably not, but here's how it happened:
BlueJ launches extensions using a ClassLoader designed to separate
extensions from each other and provide them with a "clean" view of their
environment. This seems desirable -- we have had problems in the past
with extensions accidentally sharing a parser library with BlueJ itself.
We certainly don't want separately developed extensions to share a
ClassLoader with each other.
But callbacks into extensions are (by and large) made on BlueJ's AWT
event dispatch thread, which was loaded by BlueJ when it started, and so
has a completely different ClassLoader (which really shouldn't be
visible to extensions).
I suspect that callbacks to extensions should be disptached from a
thread which shares the extension's ClassLoader, but we'll need to give
some thoughts to the implications of that. I have (still in my inbox) a
detailed note from Davin about other "dispatch thread" issues in
extensions, and potential deadlocks arising from them.
I'm not sure that we can entirely fix the problem you've identified
(bluej.getCurrentFrame().getClass().getClassLoader()?), but we should at
least document the problem to save those who follow the pain you must
have suffered.
Ian.
More information about the bluej-discuss
mailing list