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:59:35 UTC
svn commit: r894914 - in /velocity/engine/trunk/src: changes/changes.xml
java/org/apache/velocity/runtime/directive/Define.java
test/org/apache/velocity/test/issues/Velocity727TestCase.java
Author: nbubna
Date: Thu Dec 31 17:59:34 2009
New Revision: 894914
URL: http://svn.apache.org/viewvc?rev=894914&view=rev
Log:
VELOCITY-727 give informative exception when the key parameter is not given to #define (thanks to Jarkko Viinamaki)
Added:
velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity727TestCase.java (with props)
Modified:
velocity/engine/trunk/src/changes/changes.xml
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Define.java
Modified: velocity/engine/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/changes/changes.xml?rev=894914&r1=894913&r2=894914&view=diff
==============================================================================
--- velocity/engine/trunk/src/changes/changes.xml (original)
+++ velocity/engine/trunk/src/changes/changes.xml Thu Dec 31 17:59:34 2009
@@ -26,6 +26,10 @@
<body>
<release version="1.7" date="In Subversion">
+ <action type="fix" dev="nbubna" issue="VELOCITY-727" due-to="Jarkko Viinamäki">
+ Throw an informative VelocityException when #define is given no parameter (instead of an ArrayIndexOutOfBoundsException).
+ </action>
+
<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>
Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Define.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Define.java?rev=894914&r1=894913&r2=894914&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Define.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Define.java Thu Dec 31 17:59:34 2009
@@ -22,6 +22,8 @@
import java.io.Writer;
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.TemplateInitException;
+import org.apache.velocity.exception.VelocityException;
+import org.apache.velocity.runtime.log.Log;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.parser.node.Node;
@@ -53,6 +55,13 @@
{
super.init(rs, context, node);
+ // the first child is the block name (key), the second child is the block AST body
+ if ( node.jjtGetNumChildren() != 2 )
+ {
+ throw new VelocityException("parameter missing: block name at "
+ + Log.formatFileString(this));
+ }
+
/*
* first token is the name of the block. We don't even check the format,
* just assume it looks like this: $block_name. Should we check if it has
Added: velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity727TestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity727TestCase.java?rev=894914&view=auto
==============================================================================
--- velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity727TestCase.java (added)
+++ velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity727TestCase.java Thu Dec 31 17:59:34 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-727.
+ */
+public class Velocity727TestCase extends BaseTestCase
+{
+ public Velocity727TestCase(String name)
+ {
+ super(name);
+ DEBUG = false;
+ }
+
+ public void testDefineWithNoArgument()
+ {
+ assertEvalException("#define() foo bar #end", VelocityException.class);
+ }
+}
Propchange: velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity727TestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity727TestCase.java
------------------------------------------------------------------------------
svn:keywords = Revision
Propchange: velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity727TestCase.java
------------------------------------------------------------------------------
svn:mime-type = text/plain