Thread.getContextClassLoader() == null?

若如初见. 提交于 2019-12-07 02:48:49

问题


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 does not work in this case (and my code does setContextClassLoader(null)


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/225594/thread-getcontextclassloader-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!