#1026 new
Jan Thomä

#{fixture} tag breaks template rendering

Reported by Jan Thomä | August 10th, 2011 @ 06:54 AM

Framework version: Play 1.2.1, Play 1.2.2

Platform you're using: Mac OS X 10.6 and 10.7, Java 1.6

Details:

I am developing an application in play and in my selenium tests I use several tags for repetitive tasks. Two tags are:

app/views/tags/loginAs.html

*{ Tag for running selenium tests when being logged in }*

#{if !_keepData}
#{braindumpFixture delete:'all', load:'users.yml' /}
#{/if}

#{selenium}
 ... some selenium code to log into the application
#{/selenium}

app/views/tags/braindumpFixture.html

%{
if(_delete == 'all') {
play.test.Fixtures.deleteAll()
} else if(_delete) {
play.test.Fixtures.delete(_delete)
}
}%

%{
if(_load) {
play.test.Fixtures.load(_load)
}
// finally make sure the index is correctly updated.
new application.jobs.CompleteReindexJob().doJob();
}%

These work without a problem in Play 1.1. After switching to play 1.2.1 or 1.2.2, I get the following exception when running a selenium test that uses loginAs, eg.:

test/selenium/AddCard.test.html

*{ Tests adding a simple card }*

#{loginAs login:'admin@insomnia-hq.de', password:'admin' /}

#{selenium}
open('@{Application.index()}')
... more selenium stuff here
#{/selenium}

The exception is:

@67c5gib0k
Internal Server Error (500) for request GET /@tests/selenium/AddCard.test.html?thisIsChrome=false&thisIsHTA=false

Template execution error (In /app/views/tags/loginAs.html around line null)
Execution error occured in template /app/views/tags/loginAs.html. Exception raised was NullPointerException : Cannot get property 'data' on null object.

play.exceptions.TemplateExecutionException: Cannot get property 'data' on null object
    at play.templates.BaseTemplate.throwException(BaseTemplate.java:84)
    at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:252)
    at play.templates.GroovyTemplate$ExecutableTemplate.invokeTag(GroovyTemplate.java:374)
    at /test/selenium/AddCard.test.html.(line:3)
    at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:229)
    at play.templates.Template.render(Template.java:26)
    at play.templates.GroovyTemplate.render(GroovyTemplate.java:184)
    at controllers.TestRunner.run(TestRunner.java:107)
    at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:543)
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:499)
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:475)
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:470)
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:158)
    at Invocation.HTTP Request(Play!)
Caused by: java.lang.NullPointerException: Cannot get property 'data' on null object
    at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:229)
    ... 12 more

When I remove the #{if !_keepData} around the call to braindumpFixture I get an EmptyStackException:


@67c5gib0j
Internal Server Error (500) for request GET /@tests/selenium/AddCard.test.html?thisIsChrome=false&thisIsHTA=false

Template execution error (In /test/selenium/AddCard.test.html around line 3)
Execution error occured in template /test/selenium/AddCard.test.html. Exception raised was EmptyStackException : null.

play.exceptions.TemplateExecutionException
    at play.templates.BaseTemplate.throwException(BaseTemplate.java:84)
    at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:252)
    at play.templates.Template.render(Template.java:26)
    at play.templates.GroovyTemplate.render(GroovyTemplate.java:184)
    at controllers.TestRunner.run(TestRunner.java:107)
    at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:543)
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:499)
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:475)
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:470)
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:158)
    at Invocation.HTTP Request(Play!)
Caused by: java.util.EmptyStackException
    at java.util.Stack.peek(Stack.java:85)
    at java.util.Stack.pop(Stack.java:67)
    at play.templates.TagContext.exitTag(TagContext.java:31)
    at play.templates.GroovyTemplate$ExecutableTemplate.invokeTag(GroovyTemplate.java:380)
    at /test/selenium/AddCard.test.html.(line:3)
    at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:229)
    ... 9 more

I read the changelog and documentation and there seems to be no fundamental change that would forbid using tags inside tags, so I wonder if this might be a bug.

Comments and changes to this ticket

  • Jan Thomä

    Jan Thomä December 15th, 2011 @ 04:56 PM

    It seems to be the #{fixture} tag. When I include something with #{include} that has a #{fixture} inside, i also get the EmptyStackException.

  • Jan Thomä

    Jan Thomä February 7th, 2012 @ 07:25 PM

    • Title changed from “Using Tags inside Tags is broken since Play 1.2.1” to “#{fixture} tag breaks template rendering”

    Okay, it's definitely the fixture tag. When you load a fixture using the #{fixture} tag (the bundled tag, not my own implementation), Fixtures.load will use the template renderer to load the yml-file to load

    // Fixtures.java
    
    168            String renderedYaml = TemplateLoader.load(yamlFile).render();
    

    This starts the rendering process. However somewhere deep in GroovyTemplate.java

    
    // GroovyTemplate.java
    
    222        if (!args.containsKey("_body") && !args.containsKey("_isLayout") && !args.containsKey("_isInclude")) {
    223            layoutData.set(new HashMap<Object, Object>());
    224            TagContext.init();
    225       }
    

    This will kill the complete TagContext which will in turn lead to said NPEs, as when the rendering continues, the stack no longer exists. A fix would be to do

    // Fixtures.java
    
    168            String renderedYaml = TemplateLoader.load(yamlFile).render(Collections.singletonMap("isInclude", true));
    

    which should cure the issues. I'm not too sure if this is a hack though.

  • Jan Thomä

    Jan Thomä February 7th, 2012 @ 07:42 PM

    As a workaround you can modify the fixture tag to save/restore the stack:

    %{
        if(_delete == 'all') {
            play.test.Fixtures.deleteAll()
        } else if(_delete) {
            play.test.Fixtures.delete(_delete)
        }
    }%
    
    %{
        if(_load) {
            // Workaround (save the stack)
            stack = play.templates.TagContext.currentStack.get();
    
            play.test.Fixtures.load(_load)
    
            // Workaround (restore the stack)
            play.templates.TagContext.currentStack.set(stack);
        }
    }%
    
    %{
        if(_arg && _arg instanceof String) {
            try {
                play.Play.classloader.loadClass(_arg).newInstance()
            } catch(Exception e) {
                throw new play.exceptions.TagInternalException('Cannot apply ' + _arg + ' fixture because of ' + e.getClass().getName() + ', ' + e.getMessage())
            }
        }
    %}
    
  • Alex

    Alex September 30th, 2013 @ 09:36 AM

    • Tag set to fixtures, tag

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Play framework

Play makes it easier to build Web applications with Java. It is a clean alternative to bloated Enterprise Java stacks. It focuses on developer productivity and targets RESTful architectures. Learn more on the http://www.playframework.org website.

Source code is hosted on github

Check out our repository at http://github.com/playframework/play

Contributing, creating a patch

Please read the contributor guide

Reporting Security Vulnerabilities

Since all bug reports are public, please report any security vulnerability directly to guillaume dot bort at gmail dot com.

Creating a bug report

Bug reports are incredibly helpful, so take time to report bugs and request features in our ticket tracker. We’re always grateful for patches to Play’s code. Indeed, bug reports with attached patches will get fixed far quickly than those without any.

Please include as much relevant information as possible including the exact framework version you're using and a code snippet that reproduces the problem.

Don't have too much expectations. Unless the bug is really a serious "everything is broken" thing, you're creating a ticket to start a discussion. Having a patch (or a branch on Github we can pull from) is better, but then again we'll only pull high quality branches that make sense to be in the core of Play.

Shared Ticket Bins

People watching this ticket

Tags

Pages