BugRat Report # 157

Project: Jasper Release: tomcat 3.1, 4.0
Category: Bug Report SubCategory: New Bug Report
Class: swbug State: received
Priority: low Severity: critical
Confidence: public

Submitter: Tom May ( tom@go2net.com )
Date Submitted: Sep 22 2000, 06:24:07 CDT
Responsible: Z_Tomcat Alias ( tomcat-bugs@cortexity.com )

_jspx_init() handling is not thread safe
Environment: (jvm, os, osrel, platform)
any, any, any, any

Additional Environment Description:

Report Description:
JSP pages are translated java code containing the following fragments: private static boolean _jspx_inited = false; public final void _jspx_init() throws JasperException { } public void _jspService(HttpServletRequest request, HttpServletResponse re\ sponse) throws IOException, ServletException { try { if (_jspx_inited == false) { _jspx_init(); _jspx_inited = true; } This is not thread-safe. The "if" block needs to be synchronized to avoid surprising results. This is true even if the operations performed by _jspx_init() are idempotent and create only immutable objects. As is, the code will likely work most of the time on most java implementations but it won't work right all of the time on all java implementations. See the Java Language Specification chapter 17 for a description of the java memory model and some examples of surprising results caused by lack of synchronization. And keep in mind that the "java memory model" includes code motion performed by the java compiler and jit as well as by the hardware.

View this report online...