You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by wg...@apache.org on 2006/01/04 06:45:55 UTC
svn commit: r365832 - in /jakarta/velocity/core/trunk:
src/java/org/apache/velocity/ src/java/org/apache/velocity/app/
src/java/org/apache/velocity/runtime/directive/
src/java/org/apache/velocity/runtime/parser/node/
src/test/org/apache/velocity/test/ ...
Author: wglass
Date: Tue Jan 3 21:45:40 2006
New Revision: 365832
URL: http://svn.apache.org/viewcvs?rev=365832&view=rev
Log:
Pass through RuntimeExceptions from plugins and event handlers.
(except for MethodExceptionEventHandler). VELOCITY-429.
Added:
jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/ExceptionTestCase.java (with props)
jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/ExceptionGeneratingDirective.java (with props)
jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/ExceptionGeneratingEventHandler.java (with props)
jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/ExceptionGeneratingResourceLoader.java (with props)
Modified:
jakarta/velocity/core/trunk/src/java/org/apache/velocity/Template.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/Velocity.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/VelocityEngine.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Include.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Parse.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/VMProxyArg.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/BooleanPropertyExecutor.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java
jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/UberspectTestException.java
jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/UberspectTestImpl.java
jakarta/velocity/core/trunk/xdocs/changes.xml
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/Template.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/Template.java?rev=365832&r1=365831&r2=365832&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/Template.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/Template.java Tue Jan 3 21:45:40 2006
@@ -16,23 +16,20 @@
* limitations under the License.
*/
-import java.io.InputStream;
-import java.io.Writer;
import java.io.BufferedReader;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
+import java.io.Writer;
-import org.apache.velocity.runtime.resource.Resource;
-import org.apache.velocity.runtime.parser.ParseException;
-import org.apache.velocity.runtime.parser.node.SimpleNode;
-
-import org.apache.velocity.VelocityContext;
import org.apache.velocity.context.Context;
import org.apache.velocity.context.InternalContextAdapterImpl;
-
-import org.apache.velocity.exception.ResourceNotFoundException;
-import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.runtime.parser.ParseException;
+import org.apache.velocity.runtime.parser.node.SimpleNode;
+import org.apache.velocity.runtime.resource.Resource;
/**
* This class is used for controlling all template
@@ -134,6 +131,13 @@
*/
errorCondition = new ParseErrorException( pex );
throw errorCondition;
+ }
+ /**
+ * pass through runtime exceptions
+ */
+ catch( RuntimeException e )
+ {
+ throw e;
}
catch( Exception e )
{
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/Velocity.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/Velocity.java?rev=365832&r1=365831&r2=365832&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/Velocity.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/Velocity.java Tue Jan 3 21:45:40 2006
@@ -16,31 +16,28 @@
* limitations under the License.
*/
-import java.io.Writer;
-import java.util.Properties;
-import java.io.InputStream;
+import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.Reader;
-import java.io.BufferedReader;
import java.io.StringReader;
-import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+import java.util.Properties;
-import org.apache.velocity.context.Context;
+import org.apache.commons.collections.ExtendedProperties;
import org.apache.velocity.Template;
+import org.apache.velocity.context.Context;
import org.apache.velocity.context.InternalContextAdapterImpl;
-import org.apache.velocity.runtime.log.Log;
-import org.apache.velocity.runtime.RuntimeSingleton;
-import org.apache.velocity.runtime.RuntimeConstants;
-import org.apache.velocity.runtime.parser.node.SimpleNode;
-
-import org.apache.velocity.exception.ResourceNotFoundException;
-import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.MethodInvocationException;
-
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.runtime.RuntimeConstants;
+import org.apache.velocity.runtime.RuntimeSingleton;
+import org.apache.velocity.runtime.log.Log;
import org.apache.velocity.runtime.parser.ParseException;
-
-import org.apache.commons.collections.ExtendedProperties;
+import org.apache.velocity.runtime.parser.node.SimpleNode;
/**
* This class provides services to the application
@@ -374,7 +371,26 @@
return retval;
}
- catch( Exception e )
+ /**
+ * pass through application level runtime exceptions
+ */
+ catch( RuntimeException e )
+ {
+ throw e;
+ }
+ catch( ParseErrorException e )
+ {
+ RuntimeSingleton.error( "Velocity.invokeVelocimacro() : error " + e );
+ }
+ catch( MethodInvocationException e )
+ {
+ RuntimeSingleton.error( "Velocity.invokeVelocimacro() : error " + e );
+ }
+ catch( ResourceNotFoundException e )
+ {
+ RuntimeSingleton.error( "Velocity.invokeVelocimacro() : error " + e );
+ }
+ catch( IOException e )
{
RuntimeSingleton.error( "Velocity.invokeVelocimacro() : error " + e );
}
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/VelocityEngine.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/VelocityEngine.java?rev=365832&r1=365831&r2=365832&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/VelocityEngine.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/VelocityEngine.java Tue Jan 3 21:45:40 2006
@@ -16,31 +16,28 @@
* limitations under the License.
*/
-import java.io.Writer;
-import java.util.Properties;
-import java.io.InputStream;
+import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.Reader;
-import java.io.BufferedReader;
import java.io.StringReader;
-import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+import java.util.Properties;
-import org.apache.velocity.context.Context;
+import org.apache.commons.collections.ExtendedProperties;
import org.apache.velocity.Template;
+import org.apache.velocity.context.Context;
import org.apache.velocity.context.InternalContextAdapterImpl;
-import org.apache.velocity.runtime.RuntimeInstance;
+import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.runtime.RuntimeConstants;
+import org.apache.velocity.runtime.RuntimeInstance;
import org.apache.velocity.runtime.log.Log;
-import org.apache.velocity.runtime.parser.node.SimpleNode;
-
-import org.apache.velocity.exception.ResourceNotFoundException;
-import org.apache.velocity.exception.ParseErrorException;
-import org.apache.velocity.exception.MethodInvocationException;
-
import org.apache.velocity.runtime.parser.ParseException;
-
-import org.apache.commons.collections.ExtendedProperties;
+import org.apache.velocity.runtime.parser.node.SimpleNode;
/**
* <p>
@@ -330,6 +327,13 @@
{
nodeTree.init( ica, ri );
}
+ /**
+ * pass through application level runtime exceptions
+ */
+ catch( RuntimeException e )
+ {
+ throw e;
+ }
catch( Exception e )
{
ri.getLog().error("Velocity.evaluate() : init exception for tag = "
@@ -418,6 +422,13 @@
logTag, construct.toString() );
return retval;
+ }
+ /**
+ * pass through application level runtime exceptions
+ */
+ catch( RuntimeException e )
+ {
+ throw e;
}
catch( Exception e )
{
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java?rev=365832&r1=365831&r2=365832&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java Tue Jan 3 21:45:40 2006
@@ -16,29 +16,22 @@
* limitations under the License.
*/
-import java.io.Writer;
import java.io.IOException;
-
+import java.io.Writer;
import java.util.Iterator;
import org.apache.velocity.app.event.EventCartridge;
-
-import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.context.Context;
-
-import org.apache.velocity.runtime.resource.Resource;
-
-import org.apache.velocity.runtime.RuntimeServices;
-import org.apache.velocity.runtime.RuntimeConstants;
-
-import org.apache.velocity.runtime.parser.node.Node;
-import org.apache.velocity.runtime.parser.node.SimpleNode;
-import org.apache.velocity.runtime.parser.node.ASTReference;
-
+import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
-
+import org.apache.velocity.runtime.RuntimeConstants;
+import org.apache.velocity.runtime.RuntimeServices;
+import org.apache.velocity.runtime.parser.node.ASTReference;
+import org.apache.velocity.runtime.parser.node.Node;
+import org.apache.velocity.runtime.parser.node.SimpleNode;
+import org.apache.velocity.runtime.resource.Resource;
import org.apache.velocity.util.introspection.Info;
import org.apache.velocity.util.introspection.IntrospectionCacheData;
@@ -364,6 +357,13 @@
try
{
i = rsvc.getUberspect().getIterator(listObject, uberInfo);
+ }
+ /**
+ * pass through application level runtime exceptions
+ */
+ catch( RuntimeException e )
+ {
+ throw e;
}
catch(Exception ee)
{
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Include.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Include.java?rev=365832&r1=365831&r2=365832&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Include.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Include.java Tue Jan 3 21:45:40 2006
@@ -217,6 +217,13 @@
throw rnfe;
}
+ /**
+ * pass through application level runtime exceptions
+ */
+ catch( RuntimeException e )
+ {
+ throw e;
+ }
catch (Exception e)
{
rsvc.getLog().error("#include(): arg = '" + arg +
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Parse.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Parse.java?rev=365832&r1=365831&r2=365832&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Parse.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Parse.java Tue Jan 3 21:45:40 2006
@@ -179,6 +179,13 @@
throw pee;
}
+ /**
+ * pass through application level runtime exceptions
+ */
+ catch( RuntimeException e )
+ {
+ throw e;
+ }
catch ( Exception e)
{
rsvc.getLog().error("#parse() : arg = " + arg + '.', e);
@@ -195,23 +202,23 @@
((SimpleNode) t.getData()).render( context, writer );
}
}
- catch ( Exception e )
+ /**
+ * pass through application level runtime exceptions
+ */
+ catch( RuntimeException e )
{
- /*
- * if it's a MIE, it came from the render.... throw it...
- */
-
- if ( e instanceof MethodInvocationException)
- {
- throw (MethodInvocationException) e;
- }
-
- // Also throw Runtime Exceptions up the chain. Should fix VELOCITY-424.
- if (e instanceof RuntimeException)
- {
- throw (RuntimeException) e;
- }
+ throw e;
+ }
+ /*
+ * if it's a MIE, it came from the render.... throw it...
+ */
+ catch( MethodInvocationException e )
+ {
+ throw e;
+ }
+ catch ( Exception e )
+ {
rsvc.getLog().error("Exception rendering #parse(" + arg + ')', e);
return false;
}
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/VMProxyArg.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/VMProxyArg.java?rev=365832&r1=365831&r2=365832&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/VMProxyArg.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/VMProxyArg.java Tue Jan 3 21:45:40 2006
@@ -19,6 +19,7 @@
import java.io.BufferedReader;
import java.io.StringReader;
import java.io.StringWriter;
+
import org.apache.velocity.VelocityContext;
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.context.InternalContextAdapterImpl;
@@ -318,6 +319,13 @@
retObject = writer;
}
+ /**
+ * pass through application level runtime exceptions
+ */
+ catch( RuntimeException e )
+ {
+ throw e;
+ }
catch (Exception e )
{
log.error("VMProxyArg.getObject() : error rendering reference", e);
@@ -418,6 +426,13 @@
nodeTree.init(ica, rsvc);
}
+ /**
+ * pass through application level runtime exceptions
+ */
+ catch( RuntimeException e )
+ {
+ throw e;
+ }
catch ( Exception e )
{
log.error("VMProxyArg.setup() : exception " +
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java?rev=365832&r1=365831&r2=365832&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java Tue Jan 3 21:45:40 2006
@@ -21,6 +21,7 @@
import java.io.StringReader;
import java.io.Writer;
import java.util.HashMap;
+
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.context.VMContext;
import org.apache.velocity.exception.MethodInvocationException;
@@ -171,16 +172,24 @@
rsvc.getLog().error("VM error " + macroName + ". Null AST");
}
}
- catch ( Exception e )
+ /**
+ * pass through application level runtime exceptions
+ */
+ catch( RuntimeException e )
{
- /*
- * if it's a MIE, it came from the render.... throw it...
- */
+ throw e;
+ }
- if ( e instanceof MethodInvocationException)
- {
- throw (MethodInvocationException) e;
- }
+ /*
+ * if it's a MIE, it came from the render.... throw it...
+ */
+ catch( MethodInvocationException e )
+ {
+ throw e;
+ }
+
+ catch ( Exception e )
+ {
rsvc.getLog().error("VelocimacroProxy.render() : exception VM = #" +
macroName + "()", e);
@@ -295,6 +304,13 @@
VMReferenceMungeVisitor v = new VMReferenceMungeVisitor( hm );
nodeTree.jjtAccept( v, null );
}
+ /**
+ * pass through application level runtime exceptions
+ */
+ catch( RuntimeException e )
+ {
+ throw e;
+ }
catch ( Exception e )
{
rsvc.getLog().error("VelocimacroManager.parseTree() : exception " +
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java?rev=365832&r1=365831&r2=365832&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java Tue Jan 3 21:45:40 2006
@@ -133,6 +133,14 @@
}
}
}
+
+ /**
+ * pass through application level runtime exceptions
+ */
+ catch( RuntimeException e )
+ {
+ throw e;
+ }
catch(Exception e)
{
log.error("ASTIdentifier.execute() : identifier = "+identifier, e);
@@ -170,7 +178,13 @@
return EventHandlerUtil.methodException(rsvc, context, o.getClass(), vg.getMethodName(),
(Exception) t);
}
- catch(Exception e)
+
+ /**
+ * If the event handler throws an exception, then wrap it
+ * in a MethodInvocationException. Don't pass through RuntimeExceptions like other
+ * similar catchall code blocks.
+ */
+ catch( Exception e )
{
throw new MethodInvocationException(
"Invocation of method '" + vg.getMethodName() + "'"
@@ -201,6 +215,13 @@
catch(IllegalArgumentException iae)
{
return null;
+ }
+ /**
+ * pass through application level runtime exceptions
+ */
+ catch( RuntimeException e )
+ {
+ throw e;
}
catch(Exception e)
{
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java?rev=365832&r1=365831&r2=365832&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java Tue Jan 3 21:45:40 2006
@@ -184,6 +184,13 @@
throw mie;
}
+ /**
+ * pass through application level runtime exceptions
+ */
+ catch( RuntimeException e )
+ {
+ throw e;
+ }
catch( Exception e )
{
/*
@@ -238,6 +245,12 @@
{
return EventHandlerUtil.methodException( rsvc, context, o.getClass(), methodName, (Exception) t );
}
+
+ /**
+ * If the event handler throws an exception, then wrap it
+ * in a MethodInvocationException. Don't pass through RuntimeExceptions like other
+ * similar catchall code blocks.
+ */
catch( Exception e )
{
throw new MethodInvocationException(
@@ -266,6 +279,13 @@
+ ite.getTargetException().getMessage(),
ite.getTargetException(), methodName );
}
+ }
+ /**
+ * pass through application level runtime exceptions
+ */
+ catch( RuntimeException e )
+ {
+ throw e;
}
catch( Exception e )
{
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java?rev=365832&r1=365831&r2=365832&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java Tue Jan 3 21:45:40 2006
@@ -416,6 +416,13 @@
+ ite.getTargetException().getClass(),
ite.getTargetException(), identifier );
}
+ /**
+ * pass through application level runtime exceptions
+ */
+ catch( RuntimeException e )
+ {
+ throw e;
+ }
catch(Exception e)
{
/*
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java?rev=365832&r1=365831&r2=365832&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java Tue Jan 3 21:45:40 2006
@@ -17,10 +17,14 @@
*/
import java.io.BufferedReader;
+import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.parser.Parser;
import org.apache.velocity.runtime.parser.ParserVisitor;
@@ -191,14 +195,30 @@
return ret;
}
}
- catch(Exception e)
+ /**
+ * pass through application level runtime exceptions
+ */
+ catch( RuntimeException e )
+ {
+ throw e;
+ }
+ catch( ParseErrorException e )
+ {
+ log.error("Error in interpolating string literal", e);
+ }
+ catch( MethodInvocationException e )
{
- /*
- * eh. If anything wrong, just punt
- * and output the literal
- */
log.error("Error in interpolating string literal", e);
}
+ catch( ResourceNotFoundException e )
+ {
+ log.error("Error in interpolating string literal", e);
+ }
+ catch( IOException e )
+ {
+ log.error("Error in interpolating string literal", e);
+ }
+
}
/*
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/BooleanPropertyExecutor.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/BooleanPropertyExecutor.java?rev=365832&r1=365831&r2=365832&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/BooleanPropertyExecutor.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/BooleanPropertyExecutor.java Tue Jan 3 21:45:40 2006
@@ -15,11 +15,10 @@
* limitations under the License.
*/
-import org.apache.velocity.util.introspection.Introspector;
-
+import org.apache.velocity.runtime.RuntimeLogger;
import org.apache.velocity.runtime.log.Log;
import org.apache.velocity.runtime.log.RuntimeLoggerLog;
-import org.apache.velocity.runtime.RuntimeLogger;
+import org.apache.velocity.util.introspection.Introspector;
/**
* Handles discovery and valuation of a
@@ -86,6 +85,13 @@
method = null;
}
+ }
+ /**
+ * pass through application level runtime exceptions
+ */
+ catch( RuntimeException e )
+ {
+ throw e;
}
catch(Exception e)
{
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java?rev=365832&r1=365831&r2=365832&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java Tue Jan 3 21:45:40 2006
@@ -17,10 +17,10 @@
import java.lang.reflect.InvocationTargetException;
-import org.apache.velocity.util.introspection.Introspector;
+import org.apache.velocity.runtime.RuntimeLogger;
import org.apache.velocity.runtime.log.Log;
import org.apache.velocity.runtime.log.RuntimeLoggerLog;
-import org.apache.velocity.runtime.RuntimeLogger;
+import org.apache.velocity.util.introspection.Introspector;
/**
* Returned the value of object property when executed.
@@ -105,6 +105,13 @@
return;
}
+ }
+ /**
+ * pass through application level runtime exceptions
+ */
+ catch( RuntimeException e )
+ {
+ throw e;
}
catch(Exception e)
{
Added: jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/ExceptionTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/ExceptionTestCase.java?rev=365832&view=auto
==============================================================================
--- jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/ExceptionTestCase.java (added)
+++ jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/ExceptionTestCase.java Tue Jan 3 21:45:40 2006
@@ -0,0 +1,178 @@
+package org.apache.velocity.test;
+
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed 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 java.io.StringWriter;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.context.Context;
+import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.runtime.RuntimeConstants;
+import org.apache.velocity.test.misc.ExceptionGeneratingDirective;
+import org.apache.velocity.test.misc.ExceptionGeneratingEventHandler;
+import org.apache.velocity.test.misc.ExceptionGeneratingResourceLoader;
+import org.apache.velocity.test.provider.TestProvider;
+
+/**
+ * Test case for miscellaneous Exception related issues.
+ *
+ * @author <a href="mailto:wglass@forio.com">Will Glass-Husain</a>
+ * @version $Id$
+ */
+public class ExceptionTestCase extends BaseTestCase implements TemplateTestBase
+{
+ VelocityEngine ve;
+
+ /**
+ * Default constructor.
+ */
+ public ExceptionTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite ()
+ {
+ return new TestSuite(ExceptionTestCase.class);
+ }
+
+
+ public void testReferenceInsertionEventHandlerException()
+ throws Exception
+ {
+ ve = new VelocityEngine();
+ ve.setProperty(RuntimeConstants.EVENTHANDLER_REFERENCEINSERTION,ExceptionGeneratingEventHandler.class.getName());
+ ve.init();
+ assertException(ve);
+ }
+
+ /**
+ * Note - this is the one case where RuntimeExceptions *are not* passed through
+ * verbatim.
+ * @throws Exception
+ */
+ public void testMethodExceptionEventHandlerException()
+ throws Exception
+ {
+ ve = new VelocityEngine();
+ ve.setProperty(RuntimeConstants.EVENTHANDLER_METHODEXCEPTION,ExceptionGeneratingEventHandler.class.getName());
+ ve.init();
+ Context context = new VelocityContext();
+ context.put ("test",new TestProvider());
+ assertMethodInvocationException(ve,context,"$test.getThrow()");
+ assertMethodInvocationException(ve,context,"$test.throw");
+ }
+
+ public void testNullSetEventHandlerException()
+ throws Exception
+ {
+ ve = new VelocityEngine();
+ ve.setProperty(RuntimeConstants.EVENTHANDLER_NULLSET,ExceptionGeneratingEventHandler.class.getName());
+ ve.init();
+ assertException(ve,"#set($test = $abc)");
+ }
+
+ public void testIncludeEventHandlerException()
+ throws Exception
+ {
+ ve = new VelocityEngine();
+ ve.setProperty(RuntimeConstants.EVENTHANDLER_INCLUDE,ExceptionGeneratingEventHandler.class.getName());
+ ve.init();
+ assertException(ve,"#include('dummy')");
+ }
+
+ public void testResourceLoaderException()
+ throws Exception
+ {
+ ve = new VelocityEngine();
+ ve.setProperty(RuntimeConstants.RESOURCE_LOADER,"except");
+ ve.setProperty("except.resource.loader.class",ExceptionGeneratingResourceLoader.class.getName());
+ try
+ {
+ ve.init(); // tries to get the macro file
+ ve.getTemplate("test.txt");
+ fail("Should have thrown RuntimeException");
+ }
+ catch (RuntimeException E)
+ {
+ // do nothing
+ }
+ }
+
+
+ public void testDirectiveException()
+ throws Exception
+ {
+ ve = new VelocityEngine();
+ ve.setProperty("userdirective",ExceptionGeneratingDirective.class.getName());
+ ve.init();
+ assertException(ve,"#Exception() test #end");
+ }
+
+
+
+ public void assertException(VelocityEngine ve)
+ throws Exception
+ {
+ Context context = new VelocityContext();
+ context.put ("test","test");
+ assertException(ve,context,"this is a $test");
+ }
+
+ public void assertException(VelocityEngine ve, String input)
+ throws Exception
+ {
+ Context context = new VelocityContext();
+ context.put ("test","test");
+ assertException(ve,context,input);
+ }
+
+ public void assertException(VelocityEngine ve, Context context, String input)
+ throws Exception
+ {
+ try
+ {
+ StringWriter writer = new StringWriter();
+ ve.evaluate(context,writer,"test",input);
+ fail("Expected RuntimeException");
+ }
+ catch (RuntimeException E)
+ {
+ // do nothing
+ }
+ }
+ public void assertMethodInvocationException(VelocityEngine ve, Context context, String input)
+ throws Exception
+ {
+ try
+ {
+ StringWriter writer = new StringWriter();
+ ve.evaluate(context,writer,"test",input);
+ fail("Expected MethodInvocationException");
+ }
+ catch (MethodInvocationException E)
+ {
+ // do nothing
+ }
+ }
+
+
+}
Propchange: jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/ExceptionTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/ExceptionTestCase.java
------------------------------------------------------------------------------
svn:keywords = Id Author Date Revision
Added: jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/ExceptionGeneratingDirective.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/ExceptionGeneratingDirective.java?rev=365832&view=auto
==============================================================================
--- jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/ExceptionGeneratingDirective.java (added)
+++ jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/ExceptionGeneratingDirective.java Tue Jan 3 21:45:40 2006
@@ -0,0 +1,56 @@
+package org.apache.velocity.test.misc;
+
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed 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 java.io.IOException;
+import java.io.Writer;
+
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.runtime.directive.Directive;
+import org.apache.velocity.runtime.parser.node.Node;
+
+/**
+ * that always throws an exception. Used to test
+ * that RuntimeExceptions are passed through.
+ *
+ * @author <a href="mailto:wglass@forio.com">Will Glass-Husain</a>
+ * @version $Id$
+ */
+public class ExceptionGeneratingDirective extends Directive
+{
+
+ public String getName()
+ {
+ return "Exception";
+ }
+
+ public int getType()
+ {
+ return Directive.BLOCK;
+ }
+
+ public boolean render(InternalContextAdapter context, Writer writer, Node node)
+ throws IOException, ResourceNotFoundException, ParseErrorException,
+ MethodInvocationException
+ {
+ throw new RuntimeException("exception");
+ }
+
+}
Propchange: jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/ExceptionGeneratingDirective.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/ExceptionGeneratingDirective.java
------------------------------------------------------------------------------
svn:keywords = Id Author Date Revision
Added: jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/ExceptionGeneratingEventHandler.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/ExceptionGeneratingEventHandler.java?rev=365832&view=auto
==============================================================================
--- jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/ExceptionGeneratingEventHandler.java (added)
+++ jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/ExceptionGeneratingEventHandler.java Tue Jan 3 21:45:40 2006
@@ -0,0 +1,56 @@
+package org.apache.velocity.test.misc;
+
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed 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.app.event.IncludeEventHandler;
+import org.apache.velocity.app.event.MethodExceptionEventHandler;
+import org.apache.velocity.app.event.NullSetEventHandler;
+import org.apache.velocity.app.event.ReferenceInsertionEventHandler;
+
+/**
+ * Event handlers that always throws an exception. Used to test
+ * that RuntimeExceptions are passed through.
+ *
+ * @author <a href="mailto:wglass@forio.com">Will Glass-Husain</a>
+ * @version $Id$
+ */
+public class ExceptionGeneratingEventHandler implements IncludeEventHandler,
+ MethodExceptionEventHandler, NullSetEventHandler, ReferenceInsertionEventHandler
+{
+
+ public String includeEvent(String includeResourcePath, String currentResourcePath,
+ String directiveName)
+ {
+ throw new RuntimeException("exception");
+ }
+
+ public Object methodException(Class claz, String method, Exception e) throws Exception
+ {
+ throw new RuntimeException("exception");
+ }
+
+ public boolean shouldLogOnNullSet(String lhs, String rhs)
+ {
+ throw new RuntimeException("exception");
+ }
+
+ public Object referenceInsert(String reference, Object value)
+ {
+ throw new RuntimeException("exception");
+ }
+
+}
Propchange: jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/ExceptionGeneratingEventHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/ExceptionGeneratingEventHandler.java
------------------------------------------------------------------------------
svn:keywords = Id Author Date Revision
Added: jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/ExceptionGeneratingResourceLoader.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/ExceptionGeneratingResourceLoader.java?rev=365832&view=auto
==============================================================================
--- jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/ExceptionGeneratingResourceLoader.java (added)
+++ jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/ExceptionGeneratingResourceLoader.java Tue Jan 3 21:45:40 2006
@@ -0,0 +1,55 @@
+package org.apache.velocity.test.misc;
+
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed 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 java.io.InputStream;
+
+import org.apache.commons.collections.ExtendedProperties;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.runtime.resource.Resource;
+import org.apache.velocity.runtime.resource.loader.ResourceLoader;
+
+/**
+ * Resource Loader that always throws an exception. Used to test
+ * that RuntimeExceptions are passed through.
+ *
+ * @author <a href="mailto:wglass@forio.com">Will Glass-Husain</a>
+ * @version $Id$
+ */
+public class ExceptionGeneratingResourceLoader extends ResourceLoader
+{
+
+ public void init(ExtendedProperties configuration)
+ {
+ }
+
+ public InputStream getResourceStream(String source) throws ResourceNotFoundException
+ {
+ throw new RuntimeException("exception");
+ }
+
+ public boolean isSourceModified(Resource resource)
+ {
+ return false;
+ }
+
+ public long getLastModified(Resource resource)
+ {
+ return 0;
+ }
+
+}
Propchange: jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/ExceptionGeneratingResourceLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/ExceptionGeneratingResourceLoader.java
------------------------------------------------------------------------------
svn:keywords = Id Author Date Revision
Modified: jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/UberspectTestException.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/UberspectTestException.java?rev=365832&r1=365831&r2=365832&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/UberspectTestException.java (original)
+++ jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/UberspectTestException.java Tue Jan 3 21:45:40 2006
@@ -28,7 +28,7 @@
* @author <a href="mailto:isidore@setgame.com">Llewellyn Falco</a>
* @version $Id$
*/
-public class UberspectTestException extends Error
+public class UberspectTestException extends RuntimeException
{
/**
Modified: jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/UberspectTestImpl.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/UberspectTestImpl.java?rev=365832&r1=365831&r2=365832&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/UberspectTestImpl.java (original)
+++ jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/misc/UberspectTestImpl.java Tue Jan 3 21:45:40 2006
@@ -33,9 +33,10 @@
if (method == null)
{
- throw new UberspectTestException("Method " +
- obj.getClass().getName() + "." + methodName +
- " does not exist.", i);
+ if (obj == null)
+ throw new UberspectTestException("Can't call method '" + methodName + "' on null object",i);
+ else
+ throw new UberspectTestException("Did not find method "+ obj.getClass().getName()+"."+methodName, i);
}
return method;
@@ -47,8 +48,10 @@
if (propertyGet == null)
{
- throw new UberspectTestException("Did not find "+
- obj.getClass().getName()+"."+identifier, i);
+ if (obj == null)
+ throw new UberspectTestException("Can't call getter '" + identifier + "' on null object",i);
+ else
+ throw new UberspectTestException("Did not find "+ obj.getClass().getName()+"."+identifier, i);
}
return propertyGet;
Modified: jakarta/velocity/core/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/xdocs/changes.xml?rev=365832&r1=365831&r2=365832&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/xdocs/changes.xml (original)
+++ jakarta/velocity/core/trunk/xdocs/changes.xml Tue Jan 3 21:45:40 2006
@@ -24,6 +24,16 @@
<body>
<release version="1.5-dev" date="in Subversion">
+ <action type="update" dev="wglass" issue="VELOCITY-429" due-to="">
+ Pass through all runtime exceptions. Among other benefits, this
+ allows plugins to throw a runtime exception to signify an application
+ level problem in the calling application.
+ </action>
+
+ <action type="fix" dev="wglass" issue="VELOCITY-98" due-to="Michal Chmielewski">
+ When #include was followed by #parse with the same file name, a ClassCastException was thrown.
+ </action>
+
<action type="add" dev="wglass" issue="VELOCITY-425" due-to="Llewellyn Falco">
Wrapped exceptions now have Cause property set on JDK 1.4. (note that Velocity
continues to run under JDK 1.3).
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org