You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Ford, Peter" <Pe...@travelocity.com> on 2004/08/12 17:41:32 UTC

Bug in nested #parse()

There seems to be a problem in Velocity in which exceptions thrown during processing of nested #parse() calls do not get passed to the calling code. It is very simple to reproduce - just compile the following and set up a couple of test files. 

Test program source:

public class Test
{
    public static void main(String[] args)
    {
        try
        {
            String resource = args[0];
            VelocityContext context = new VelocityContext(new Properties());
            context.put("firstName", "Pete");
            VelocityEngine ve = new VelocityEngine();
            Properties velCfg = new Properties();
            ve.init(velCfg);
            Writer w = new StringWriter();
            ve.mergeTemplate(resource, context, w);
            System.out.println(w.toString());
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

test file 1 ("basic.txt"):

#parse( "no-such-file.txt" )

test file 2 ("wrapper.txt"):

#parse( "basic.txt" )

Now run the program using "basic.txt" as the argument; you'll see an exception thrown because the engine can't find "no-such-file.txt". So far so good.

Run it again using "wrapper.txt" as the argument; this time no exception is thrown. The mergeTemplate() call returns to the caller as if nothing is wrong.

This is causing me serious headaches and I have to find a solution or workround. Is this a known bug? Does anyone know of a fix?

I'm running on RedHat 9. Velocity 1.3.1 and 1.4 both behave the same way.

--Pete

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Bug in nested #parse()

Posted by Kishore Senji <ks...@gmail.com>.
On Thu, 12 Aug 2004 10:41:32 -0500, Ford, Peter
<pe...@travelocity.com> wrote:
> There seems to be a problem in Velocity in which exceptions thrown during processing of nested #parse() calls do not get passed to the calling code. It is very simple to reproduce - just compile the following and set up a couple of test files.
> 
> Test program source:
> 
> public class Test
> {
>    public static void main(String[] args)
>    {
>        try
>        {
>            String resource = args[0];
>            VelocityContext context = new VelocityContext(new Properties());
>            context.put("firstName", "Pete");
>            VelocityEngine ve = new VelocityEngine();
>            Properties velCfg = new Properties();
>            ve.init(velCfg);
>            Writer w = new StringWriter();
>            ve.mergeTemplate(resource, context, w);
>            System.out.println(w.toString());
>        }
>        catch (Exception e)
>        {
>            e.printStackTrace();
>        }
>    }
> }
> 
> test file 1 ("basic.txt"):
> 
> #parse( "no-such-file.txt" )
> 
> test file 2 ("wrapper.txt"):
> 
> #parse( "basic.txt" )
> 
> Now run the program using "basic.txt" as the argument; you'll see an exception thrown because the engine can't find "no-such-file.txt". So far so good.
> 
> Run it again using "wrapper.txt" as the argument; this time no exception is thrown. The mergeTemplate() call returns to the caller as if nothing is wrong.
> 

If you look in to the Velocity.log, it does throw an
ResourceNotFoundException and ignores what ever comes in the template
after that exception.

Thanks,
Kishore Senji

> This is causing me serious headaches and I have to find a solution or workround. Is this a known bug? Does anyone know of a fix?
> 
> I'm running on RedHat 9. Velocity 1.3.1 and 1.4 both behave the same way.
> 
> --Pete
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org