Create argument error message for macros only if we need it

git-svn-id: https://svn.apache.org/repos/asf/velocity/engine/trunk@733452 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java b/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
index f77707e..0f036bd 100644
--- a/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
+++ b/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
@@ -244,6 +244,19 @@
         maxCallDepth = rsvc.getInt(RuntimeConstants.VM_MAX_DEPTH);
     }
     
+
+    /**
+     * Build an error message for not providing the correct number of arguments
+     */
+    private String buildErrorMsg(Node node)
+    {
+      int i = node.jjtGetNumChildren();  // the number of arguments this call provided
+      String msg = "VM #" + macroName + ": too "
+        + ((getNumArgs() > i) ? "few" : "many") + " arguments to macro. Wanted "
+        + getNumArgs() + " got " + i;      
+      return msg;
+    }
+    
     /**
      * check if we are calling this macro with the right number of arguments.  If 
      * we are not, and strictArguments is active, then throw TemplateInitException.
@@ -251,26 +264,23 @@
      */
     public void checkArgs(InternalContextAdapter context, Node node)
     {
-        // check how many arguments we got
+        // check how many arguments we have
         int i = node.jjtGetNumChildren();
 
         // Throw exception for invalid number of arguments?
         if (getNumArgs() != i)
         {
-            String msg = "VM #" + macroName + ": too "
-                    + ((getNumArgs() > i) ? "few" : "many") + " arguments to macro. Wanted "
-                    + getNumArgs() + " got " + i;
-
             if (strictArguments)
             {
                 /**
                  * indicate col/line assuming it starts at 0 - this will be corrected one call up
                  */
-                throw new TemplateInitException(msg, context.getCurrentTemplateName(), 0, 0);
+                throw new TemplateInitException(buildErrorMsg(node), 
+                    context.getCurrentTemplateName(), 0, 0);
             }
-            else
+            else if (rsvc.getLog().isDebugEnabled())
             {
-                rsvc.getLog().debug(msg);
+                rsvc.getLog().debug(buildErrorMsg(node));
                 return;
             }
         }