views:

480

answers:

2

Can Thread.getContextClassLoader() be null ? The javadoc is not really clear. Should a library take this case into account ?

Update: the reason I asked is that beansbinding.dev.java.net dus not work in this case (and my code does setContextClassLoader(null)

+4  A: 

Yes you should, someone could have called Thread.setContextClassLoader(null) and your library IMO should be able to deal with that.

WMR
That is a really nasty thing to do. Even classes from installed extensions wont be found with that thread context class loader.
Tom Hawtin - tackline
I don't see why that would be nasty.
Steven Devijver
+3  A: 

Java threads created from JNI code in a non-java thread have null ContextClassloader unless the creator explicitly sets it.

Also in such context Thread.currentThread() returns null.

ddimitrov