From: markt Date: Sun, 31 Aug 2008 13:47:57 +0000 (+0000) Subject: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=45691 X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=9b09939438b976511759d82d01484d6213e5c14b;p=tomcat7.0 Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=45691 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 --- diff --git a/java/org/apache/jasper/compiler/Compiler.java b/java/org/apache/jasper/compiler/Compiler.java index 6e4db637a..5e7253038 100644 --- a/java/org/apache/jasper/compiler/Compiler.java +++ b/java/org/apache/jasper/compiler/Compiler.java @@ -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()); diff --git a/java/org/apache/jasper/compiler/JspUtil.java b/java/org/apache/jasper/compiler/JspUtil.java index cc6e31765..8ebc9dfa6 100644 --- a/java/org/apache/jasper/compiler/JspUtil.java +++ b/java/org/apache/jasper/compiler/JspUtil.java @@ -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) { diff --git a/java/org/apache/jasper/compiler/Node.java b/java/org/apache/jasper/compiler/Node.java index f4a8d8f87..2aa504fdc 100644 --- a/java/org/apache/jasper/compiler/Node.java +++ b/java/org/apache/jasper/compiler/Node.java @@ -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; } diff --git a/java/org/apache/jasper/compiler/TagPluginManager.java b/java/org/apache/jasper/compiler/TagPluginManager.java index 0a2a30032..e95d0382c 100644 --- a/java/org/apache/jasper/compiler/TagPluginManager.java +++ b/java/org/apache/jasper/compiler/TagPluginManager.java @@ -191,7 +191,7 @@ public class TagPluginManager { } public String getTemporaryVariableName() { - return JspUtil.nextTemporaryVariableName(); + return node.getRoot().nextTemporaryVariableName(); } public void generateImport(String imp) {