Bug 50459 - StandardContext.bindThread() and unbindThread() are not symmetrical and not limited to current thread
Summary: StandardContext.bindThread() and unbindThread() are not symmetrical and not l...
Alias: None
Product: Tomcat 6
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 6.0.29
Hardware: All All
: P2 normal (vote)
Target Milestone: default
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2010-12-11 19:06 UTC by Sylvain Laurent
Modified: 2011-01-05 09:18 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Sylvain Laurent 2010-12-11 19:06:16 UTC
As a side effect of my commit, I think I found a bug in StandardContext.bindThread() and unbindThread() methods in both tomcat 6 and 7 :

- the methods should be symmetrical : unbindThread should restore the Thread CCL after calling DirContextURLStreamHandler.unbind() and ContextBindings.unbindThread()
- StandardContext.bindThread() should call DirContextURLStreamHandler.bindThread() instead of DirContextURLStreamHandler.bind()
- StandardContext.unbindThread() should call DirContextURLStreamHandler.unbindThread() instead of DirContextURLStreamHandler.unbind()
Comment 1 Sylvain Laurent 2010-12-11 19:09:33 UTC
oops, forgot the link to my initial commit that revealed the bug : http://svn.apache.org/viewvc?rev=1044145&view=rev
Comment 2 Sylvain Laurent 2010-12-11 19:12:12 UTC
fix committed on trunk : http://svn.apache.org/viewvc?rev=1044746&view=rev
Comment 3 Mark Thomas 2010-12-12 16:22:28 UTC
Moving to 6 now it is fixed in 7.
Comment 4 Sylvain Laurent 2010-12-12 17:56:31 UTC
patch proposed for tomcat 6
Comment 5 Konstantin Kolinko 2010-12-12 18:43:04 UTC
Looking at r1044746 and the patch proposed for TC6,
I think that that replacement of
is wrong.

See DirContextURLStreamHandler#get().

The difference is when a web application starts a child thread. That thread inherits TCCL from its parent and thus DirContextURLStreamHandler will recognize it when using CL-binding, but will not if thread-binding is used.
Comment 6 Sylvain Laurent 2010-12-13 17:42:40 UTC
Actually the TCCL is properly bound in DirContextURLStreamHandler#clBindings when the application is started : DirContextURLStreamHandler.bind(ClassLoader, DirContext) is called from WebappLoader.startInternal() which itself is called during StandardContext.startInternal() (StandardContext.java rev 1044747 line 4863)

Before my fix, it was "pure luck" that the TCCL was still bound after StandardContext.startInternal() : it only worked because the TCCL was reverted _after_ calling DirContextURLStreamHandler.unbind() so that the latter tried to remove a classloader that had not been bound previously, thus leaving the webapp classloader properly bound.
Comment 7 Konstantin Kolinko 2010-12-19 19:48:15 UTC
(In reply to comment #6)
OK, I understand it now. WebappLoader indeed manages that binding.
Comment 8 Mark Thomas 2011-01-05 09:18:11 UTC
Fixed in 6.0.x and will be included in 6.0.30 onwards.