Bug 34703 - Invalid synchronization in PageData leads to java.lang.IllegalThreadStateException
Summary: Invalid synchronization in PageData leads to java.lang.IllegalThreadStateExce...
Status: RESOLVED LATER
Alias: None
Product: Taglibs
Classification: Unclassified
Component: Scrape Taglib (show other bugs)
Version: unspecified
Hardware: All All
: P2 major (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-02 13:17 UTC by Brett Randall
Modified: 2009-11-29 19:42 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Brett Randall 2005-05-02 13:18:00 UTC
A problem with thread synchronization in org.apache.taglibs.scrape.PageData
leads to a java.lang.IllegalThreadStateException.  Looking at PageData CVS rev 1.15.

In scrapePage(), a synchronized(scraping) attempts to protect the instantiation
and start()-ing of the new Page object (Thread).  This fails however, as
scraping is an instance variable, and whilst still inside the critical section,
scraping is reassigned:

scraping = new Boolean(true);

... unprotecting the critical section.  The result is that it is possible for
two threads to attempt to start() the same page object, resulting in:

java.lang.IllegalThreadStateException
	at java.lang.Thread.start(Native Method)
	at org.apache.taglibs.scrape.PageData.scrapePage(PageData.java:549)
	at org.apache.taglibs.scrape.PageTag.doEndTag(PageTag.java:152)
	at org.apache.jsp.scrap_jsp._jspService(scrap_jsp.java:165)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:92)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:162)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)

Recommended solution: don't use "scraping" as the mutex if it needs to be
reassigned during the critical section.  A second lock Object might be more
appropriate.

As per any thread-related bug, this is difficult to reproduce, as you need two
threads to hit the expiring page at once, however in this case a review of the
code should make it clear how this problem can occur, and the fix is fairly simple.

Let me know if you need a patch submitted.
Comment 1 Henri Yandell 2009-11-29 19:42:07 UTC
Resolving. Taglib has been retired.