You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by nb...@apache.org on 2009/12/31 18:53:57 UTC

svn commit: r894911 - in /velocity/engine/trunk/src: changes/changes.xml java/org/apache/velocity/runtime/directive/Parse.java test/org/apache/velocity/test/issues/Velocity728TestCase.java

Author: nbubna
Date: Thu Dec 31 17:53:56 2009
New Revision: 894911

URL: http://svn.apache.org/viewvc?rev=894911&view=rev
Log:
VELOCITY-728 give informative exception when no arguments are given to #parse (thanks to Jarkko Viinamaki)

Added:
    velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity728TestCase.java   (with props)
Modified:
    velocity/engine/trunk/src/changes/changes.xml
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Parse.java

Modified: velocity/engine/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/changes/changes.xml?rev=894911&r1=894910&r2=894911&view=diff
==============================================================================
--- velocity/engine/trunk/src/changes/changes.xml (original)
+++ velocity/engine/trunk/src/changes/changes.xml Thu Dec 31 17:53:56 2009
@@ -26,6 +26,15 @@
 
   <body>
     <release version="1.7" date="In Subversion">
+      <action type="fix" dev="nbubna" issue="VELOCITY-728" due-to="Jarkko Viinamäki">
+    Throw an informative VelocityException when #parse is given no args (instead of an NPE).
+      </action>
+
+      <action type="fix" dev="nbubna" issue="VELOCITY-731" due-to="Jorgen Rydenius">
+    Add directive.if.tostring.nullcheck config switch to allow
+    improved performance for those who do not need to check whether
+    $foo.toString() returns null when doing #if( $foo ).
+      </action>
 
       <action type="add" dev="nbubna" issue="VELOCITY-704">
     Changed #stop to a directive implementation (get it out of the parser)

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Parse.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Parse.java?rev=894911&r1=894910&r2=894911&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Parse.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Parse.java Thu Dec 31 17:53:56 2009
@@ -129,10 +129,10 @@
         /*
          *  did we get an argument?
          */
-        if ( node.jjtGetChild(0) == null)
+        if ( node.jjtGetNumChildren() == 0 )
         {
-            rsvc.getLog().error("#parse() null argument");
-            return false;
+            throw new VelocityException("parameter missing: template name at "
+                 + Log.formatFileString(this));
         }
 
         /*

Added: velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity728TestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity728TestCase.java?rev=894911&view=auto
==============================================================================
--- velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity728TestCase.java (added)
+++ velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity728TestCase.java Thu Dec 31 17:53:56 2009
@@ -0,0 +1,40 @@
+package org.apache.velocity.test.issues;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+import org.apache.velocity.test.BaseTestCase;
+import org.apache.velocity.exception.VelocityException;
+
+/**
+ * This class tests VELOCITY-728.
+ */
+public class Velocity728TestCase extends BaseTestCase
+{
+    public Velocity728TestCase(String name)
+    {
+        super(name);
+        DEBUG = false;
+    }
+
+    public void testParseWithNoArgument()
+    {
+        assertEvalException("#parse()", VelocityException.class);
+    }
+}

Propchange: velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity728TestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity728TestCase.java
------------------------------------------------------------------------------
    svn:keywords = Revision

Propchange: velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity728TestCase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain