From 84e49aa2636e8f5358c6aea0889c58a61a73c4bd Mon Sep 17 00:00:00 2001 From: "Janek.Schumann" Date: Mon, 18 Apr 2022 00:27:55 +0200 Subject: Fixes VELOCITY-953 where VelocimacroProxy polutes context stack due to wrong handling of #break or exceptions --- .../org/apache/velocity/runtime/directive/VelocimacroProxy.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java index 0cad8a43..d3b8ff5c 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java @@ -216,8 +216,6 @@ public class VelocimacroProxy extends Directive // render the velocity macro context.pushCurrentMacroName(macroName); nodeTree.render(context, writer); - context.popCurrentMacroName(); - return true; } catch (RuntimeException e) { @@ -231,6 +229,11 @@ public class VelocimacroProxy extends Directive } finally { + // if MacroOverflowException was thrown then it already empties the stack + // for everything else - e.g. other exceptions - we clean up after ourself + if (context.getCurrentMacroCallDepth() > 0) + context.popCurrentMacroName(); + // clean up after the args and bodyRef // but only if they weren't overridden inside Object current = context.get(bodyReference); @@ -283,6 +286,8 @@ public class VelocimacroProxy extends Directive } } } + + return true; } /** -- cgit v1.2.3