You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by wg...@apache.org on 2007/10/17 06:44:19 UTC
svn commit: r585369 - in /velocity/engine/trunk/src: changes/changes.xml
java/org/apache/velocity/runtime/VelocimacroFactory.java
Author: wglass
Date: Tue Oct 16 21:44:15 2007
New Revision: 585369
URL: http://svn.apache.org/viewvc?rev=585369&view=rev
Log:
Prevent exception due to race condition with simultaneous rendering of macros. Fixes VELOCITY-566.
Modified:
velocity/engine/trunk/src/changes/changes.xml
velocity/engine/trunk/src/java/org/apache/velocity/runtime/VelocimacroFactory.java
Modified: velocity/engine/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/changes/changes.xml?rev=585369&r1=585368&r2=585369&view=diff
==============================================================================
--- velocity/engine/trunk/src/changes/changes.xml (original)
+++ velocity/engine/trunk/src/changes/changes.xml Tue Oct 16 21:44:15 2007
@@ -27,6 +27,10 @@
<body>
<release version="1.6" date="in Subversion">
+ <action type="fix" dev="wglass" issue="VELOCITY-566" due-to="Etienne Massip">
+ Prevent exception due to simultaneous rendering of macros.
+ </action>
+
<action type="fix" dev="wglass" issue="VELOCITY-536" due-to="Lei Gu, Dima Tkach">
Prevent NPE when template is parsed simultaneously by multiple users. (may apply only to macros).
</action>
Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/VelocimacroFactory.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/VelocimacroFactory.java?rev=585369&r1=585368&r2=585369&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/VelocimacroFactory.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/VelocimacroFactory.java Tue Oct 16 21:44:15 2007
@@ -147,42 +147,45 @@
*/
if (maxCallingDepth > 0)
{
- Stack macroStack = (Stack)templateMap.get(templateName);
- if (macroStack != null)
+ synchronized(templateMap)
{
- /*
- * If the macro stack size is larger than or equal to
- * maxCallingDepth allowed throw an exception
- */
- if (macroStack.size() >= maxCallingDepth)
+ Stack macroStack = (Stack)templateMap.get(templateName);
+ if (macroStack != null)
{
- log.error("Max calling depth exceded in Template:" +
- templateName + "and Macro:" + macroName);
-
- String message = "Exceed maximum " + maxCallingDepth +
- " macro calls. Call Stack:";
- /*
- * Construct the message from the stack
+ /*
+ * If the macro stack size is larger than or equal to
+ * maxCallingDepth allowed throw an exception
*/
- for (int i = 0; i < macroStack.size() - 1; i++)
+ if (macroStack.size() >= maxCallingDepth)
{
- message += macroStack.get(i) + "->";
+ log.error("Max calling depth exceded in Template:" +
+ templateName + "and Macro:" + macroName);
+
+ String message = "Exceed maximum " + maxCallingDepth +
+ " macro calls. Call Stack:";
+ /*
+ * Construct the message from the stack
+ */
+ for (int i = 0; i < macroStack.size() - 1; i++)
+ {
+ message += macroStack.get(i) + "->";
+ }
+ message += macroStack.peek();
+
+ /*
+ Clean up the template map
+ */
+ templateMap.remove(templateName);
+ throw new MacroOverflowException(message);
}
- message += macroStack.peek();
-
- /*
- Clean up the template map
- */
- templateMap.remove(templateName);
- throw new MacroOverflowException(message);
+ macroStack.push(macroName);
+ }
+ else
+ {
+ macroStack = new Stack();
+ macroStack.push(macroName);
+ templateMap.put(templateName, macroStack);
}
- macroStack.push(macroName);
- }
- else
- {
- macroStack = new Stack();
- macroStack.push(macroName);
- templateMap.put(templateName, macroStack);
}
}
}