Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

groovyTemplateEngine.writeTo(out) throws nullpointer when executed ASYNC (in a task) #14

Open
3 of 4 tasks
cdaoust opened this issue Dec 5, 2017 · 1 comment
Open
3 of 4 tasks

Comments

@cdaoust
Copy link

cdaoust commented Dec 5, 2017

Thanks for reporting an issue for Grails framework, please review the task list below before submitting the
issue. Your issue report will be closed if the issue is incomplete and the below tasks not completed.

NOTE: If you are unsure about something and the issue is more of a question a better place to ask questions is on Stack Overflow (http://stackoverflow.com/tags/grails) or Slack (http://slack-signup.grails.org). DO NOT use the issue tracker to ask questions.

Task List

  • Steps to reproduce provided
  • Stacktrace (if present) provided
  • Example that reproduces the problem uploaded to Github
  • Full description of the issue provided (see below)

Full description

We have code that processes GSP templates from a database for emails so they can be edited regularly. When using the GroovyPagesTemplateEngine within ASYNC code a nullpointer is thrown from the method writeTo(). Outside of a promise task everything works fine.

There is no stacktrace.

Steps to Reproduce

  1. take mrhaki example from blog
    http://mrhaki.blogspot.com/2010/05/grails-goodness-use-gsp-template-engine.html
    and execute within futures task

  2. Code to reproduce issue

Example service with test method that displays issue:

class TestService {
def groovyPagesTemplateEngine
void test() {
def p1 = task{

    def templateText = '''\

GSP Template Engine

This is just a sample with template text.

<g:if test="${show}">

We can use taglibs in our template!

</g:if>

  • ${item}
''' def output = new StringWriter() groovyPagesTemplateEngine.createTemplate(templateText, 'sample').make([show: true, items: ['Grails','Groovy']]).writeTo(output) output.toString() } p1.onComplete{ results -> log.info(results) } } }

Expected Behaviour

nullpointer not thrown when executed async.

Actual Behaviour

nullpointer is thrown from groovyPagesTemaplteEngine.writeTo() when executed from within promise.

Environment Information

  • Operating System: Mac OS/X
  • Grails Version: 3.2.11
  • JDK Version: 1.8
  • Container Version (If Applicable): N/A

Example Application

  • the entire example code is within this issue in steps to reproduce.

I am copying it here as well.

class TestService {
def groovyPagesTemplateEngine
void test() {
def p1 = task{

    def templateText = '''\

GSP Template Engine

This is just a sample with template text.

<g:if test="${show}">

We can use taglibs in our template!

</g:if>

  • ${item}
''' def output = new StringWriter() groovyPagesTemplateEngine.createTemplate(templateText, 'sample').make([show: true, items: ['Grails','Groovy']]).writeTo(output) output.toString() } p1.onComplete{ results -> log.info(results) } } }
@cdaoust
Copy link
Author

cdaoust commented Dec 5, 2017

A little more info - I spent some time debugging the grails/groovy code and the issue is that this is not running in the context of a web request (its scheduled) and the GSP template code is looking for the web request context/binding. So this goes back to my question I posed on the Grails slack channel - should one be able to process GSP templates outside of a web request? Perhaps I have to switch to simpler template engine?

jdaugherty pushed a commit to jdaugherty/grails-gsp that referenced this issue Jan 15, 2025
Include paramsAssertions in UrlMappings' tests and documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant