This patch fixes a race condition in the JspWrapperServlet

The cause of this race condition is the use of the Double-Checked idiom.

For more information on why the Double-Checked idiom does NOT work
please read the following
http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html

Thanks,

John Trollinger
--- /old/JspServletWrapper.java 2003-01-15 09:54:16.000000000 -0500
+++ /new/JspServletWrapper.java 2003-01-24 10:39:40.000000000 -0500
@@ -133,28 +133,27 @@
     public Servlet getServlet()
         throws ServletException, IOException, FileNotFoundException
     {
-        if (ctxt.isReload()) {
-            synchronized (this) {
-                // Synchronizing on jsw enables simultaneous loading
-                // of different pages, but not the same page.
-                if (ctxt.isReload()) {
-                    // This is to maintain the original protocol.
-                    destroy();
-                    
-                    try {
-                        servletClass = ctxt.load();
-                        theServlet = (Servlet) servletClass.newInstance();
-                    } catch( IllegalAccessException ex1 ) {
-                        throw new JasperException( ex1 );
-                    } catch( InstantiationException ex ) {
-                        throw new JasperException( ex );
-                    }
+        
+        synchronized (this) {
+            // Synchronizing on jsw enables simultaneous loading
+            // of different pages, but not the same page.
+            if (ctxt.isReload()) {
+                // This is to maintain the original protocol.
+                destroy();
                     
-                    theServlet.init(config);
-                    firstTime = false;
+                try {
+                    servletClass = ctxt.load();
+                    theServlet = (Servlet) servletClass.newInstance();
+                } catch( IllegalAccessException ex1 ) {
+                    throw new JasperException( ex1 );
+                } catch( InstantiationException ex ) {
+                    throw new JasperException( ex );
                 }
-            }    
-        }
+                    
+                theServlet.init(config);
+                firstTime = false;
+            }
+        }    
         return theServlet;
     }
 
@@ -185,9 +184,8 @@
                 }
             }
 
-            if (ctxt.isReload()) {
-                getServlet();
-            }
+            getServlet();
+            
 
             // If a page is to only to be precompiled return.
             if (precompile) {

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to