Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=45691
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 31 Aug 2008 13:47:57 +0000 (13:47 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 31 Aug 2008 13:47:57 +0000 (13:47 +0000)
Make temporary variable name generation safe when multiple compilations are running in parallel

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@690693 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/jasper/compiler/Compiler.java
java/org/apache/jasper/compiler/JspUtil.java
java/org/apache/jasper/compiler/Node.java
java/org/apache/jasper/compiler/TagPluginManager.java

index 6e4db63..5e72530 100644 (file)
@@ -145,10 +145,6 @@ public abstract class Compiler {
 
         ServletWriter writer = null;
         try {
-
-            // Reset the temporary variable counter for the generator.
-            JspUtil.resetTemporaryVariableName();
-
             // Parse the file
             ParserController parserCtl = new ParserController(ctxt, this);
             pageNodes = parserCtl.parse(ctxt.getJspFile());
index cc6e317..8ebc9df 100644 (file)
@@ -55,8 +55,6 @@ public class JspUtil {
     private static final String OPEN_EXPR_XML  = "%=";
     private static final String CLOSE_EXPR_XML = "%";
 
-    private static int tempSequenceNumber = 0;
-    
     //private static ExpressionEvaluatorImpl expressionEvaluator
     //= new ExpressionEvaluatorImpl();
     
@@ -599,22 +597,6 @@ public class JspUtil {
 //        }
     }
 
-    /**
-     * Resets the temporary variable name.
-     * (not thread-safe)
-     */
-    public static void resetTemporaryVariableName() {
-        tempSequenceNumber = 0;
-    }
-
-    /**
-     * Generates a new temporary variable name.
-     * (not thread-safe)
-     */
-    public static String nextTemporaryVariableName() {
-        return Constants.TEMP_VARIABLE_NAME_PREFIX + (tempSequenceNumber++);
-    }
-
     public static String coerceToPrimitiveBoolean(String s,
                           boolean isNamedAttribute) {
     if (isNamedAttribute) {
index f4a8d8f..2aa504f 100644 (file)
@@ -39,6 +39,7 @@ import javax.servlet.jsp.tagext.TagVariableInfo;
 import javax.servlet.jsp.tagext.TryCatchFinally;
 import javax.servlet.jsp.tagext.VariableInfo;
 
+import org.apache.jasper.Constants;
 import org.apache.jasper.JasperException;
 import org.apache.jasper.compiler.tagplugin.TagPluginContext;
 import org.xml.sax.Attributes;
@@ -470,6 +471,11 @@ abstract class Node implements TagConstants {
         private boolean isBomPresent;
 
         /*
+         * Sequence number for temporary variables.
+         */
+        private int tempSequenceNumber = 0;
+
+        /*
          * Constructor.
          */
         Root(Mark start, Node parent, boolean isXmlSyntax) {
@@ -548,6 +554,18 @@ abstract class Node implements TagConstants {
         public Root getParentRoot() {
             return parentRoot;
         }
+        
+        /**
+         * Generates a new temporary variable name.
+         */
+        public String nextTemporaryVariableName() {
+            if (parentRoot == null) {
+                return Constants.TEMP_VARIABLE_NAME_PREFIX + (tempSequenceNumber++);
+            } else {
+                return parentRoot.nextTemporaryVariableName();
+            }
+            
+        }
     }
 
     /**
@@ -1913,7 +1931,7 @@ abstract class Node implements TagConstants {
          */
         public String getTemporaryVariableName() {
             if (temporaryVariableName == null) {
-                temporaryVariableName = JspUtil.nextTemporaryVariableName();
+                temporaryVariableName = getRoot().nextTemporaryVariableName();
             }
             return temporaryVariableName;
         }
index 0a2a300..e95d038 100644 (file)
@@ -191,7 +191,7 @@ public class TagPluginManager {
         }
 
         public String getTemporaryVariableName() {
-            return JspUtil.nextTemporaryVariableName();
+            return node.getRoot().nextTemporaryVariableName();
         }
 
         public void generateImport(String imp) {