Announcement Announcement Module
Collapse
No announcement yet.
Bug in Freemark/Spring Support Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bug in Freemark/Spring Support

    I have come across a little bug (well, more of an annoyance really) where Spring does not report the true cause of the failure when a freemarker template is not parsed properly. This is a repeatable bug that I've come across at least 6 or 7 times in the last day and it can make working with Freemarker and Spring into a much frustrating endevour.

    Here is a simple template that will make it fail.
    Code:
    <#include "/lib/rns.ftl" />
    
    <@html title="$&#123;pageTitle&#125;>
    
    	<@rnsTransactionListing title="$&#123;tableTitle&#125;" transactions=rnsTransactions />
    
    </@html>
    Note, you don't need this exact page to make it fail. Notice that the title attribute is missing the ending quote: "${pageTitle}

    This is an easy mistake to make however, this gives the following exception:

    Code:
    org.springframework.context.ApplicationContextException&#58; Cannot load FreeMarker
    template for URL &#91;core\release.transactions.page.ftl&#93;&#58; Did you specify
    the correct template loader path?
    	at org.springframework.web.servlet.view.freemarker.FreeMarkerView.initApplicationContext&#40;FreeMarkerView.java&#58;136&#41;
    	at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext&#40;ApplicationObjectSupport.java&#58;79&#41;
    	at org.springframework.web.servlet.view.AbstractCachingViewResolver.loadAndConfigureView&#40;AbstractCachingViewResolver.java&#58;123&#41;
    	at org.springframework.web.servlet.view.AbstractCachingViewResolver.resolveViewName&#40;AbstractCachingViewResolver.java&#58;78&#41;
    	at org.springframework.web.servlet.DispatcherServlet.render&#40;DispatcherServlet.java&#58;629&#41;
    	at org.springframework.web.servlet.DispatcherServlet.doService&#40;DispatcherServlet.java&#58;535&#41;
    	at org.springframework.web.servlet.FrameworkServlet.service&#40;FrameworkServlet.java&#58;321&#41;
    	at javax.servlet.http.HttpServlet.service&#40;HttpServlet.java&#58;103&#41;
    	at com.caucho.server.dispatch.ServletFilterChain.doFilter&#40;ServletFilterChain.java&#58;113&#41;
    	at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage&#40;PageFilter.java&#58;129&#41;
    	at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter&#40;PageFilter.java&#58;61&#41;
    	at com.caucho.server.dispatch.FilterFilterChain.doFilter&#40;FilterFilterChain.java&#58;84&#41;
    	at com.caucho.server.cache.CacheFilterChain.doFilter&#40;CacheFilterChain.java&#58;211&#41;
    	at com.caucho.server.webapp.WebAppFilterChain.doFilter&#40;WebAppFilterChain.java&#58;177&#41;
    	at com.caucho.server.dispatch.ServletInvocation.service&#40;ServletInvocation.java&#58;221&#41;
    	at com.caucho.server.http.HttpRequest.handleRequest&#40;HttpRequest.java&#58;263&#41;
    	at com.caucho.server.port.TcpConnection.run&#40;TcpConnection.java&#58;323&#41;
    	at com.caucho.util.ThreadPool.runTasks&#40;ThreadPool.java&#58;430&#41;
    	at com.caucho.util.ThreadPool.run&#40;ThreadPool.java&#58;377&#41;
    	at java.lang.Thread.run&#40;Thread.java&#58;534&#41;
    I assure you, the loader path is not a problem. If one fixes the problem in the template, it will work fine. However, if I re-create the problem, this is what happens:

    Code:
    freemarker.core.ParseException&#58; Encountered "&#123;" at line 5, column 41.
    Was expecting&#58;
        "=" ...
        
    	at freemarker.core.FMParser.generateParseException&#40;FMParser.java&#58;4411&#41;
    	at freemarker.core.FMParser.jj_consume_token&#40;FMParser.java&#58;4286&#41;
    	at freemarker.core.FMParser.NamedArgs&#40;FMParser.java&#58;1886&#41;
    	at freemarker.core.FMParser.UnifiedMacroTransform&#40;FMParser.java&#58;1771&#41;
    	at freemarker.core.FMParser.FreemarkerDirective&#40;FMParser.java&#58;2216&#41;
    	at freemarker.core.FMParser.Content&#40;FMParser.java&#58;2433&#41;
    	at freemarker.core.FMParser.OptionalBlock&#40;FMParser.java&#58;2601&#41;
    	at freemarker.core.FMParser.Root&#40;FMParser.java&#58;2773&#41;
    	at freemarker.template.Template.<init>&#40;Template.java&#58;144&#41;
    	at freemarker.cache.TemplateCache.loadTemplate&#40;TemplateCache.java&#58;376&#41;
    	at freemarker.cache.TemplateCache.getTemplate&#40;TemplateCache.java&#58;347&#41;
    	at freemarker.cache.TemplateCache.getTemplate&#40;TemplateCache.java&#58;229&#41;
    	at freemarker.template.Configuration.getTemplate&#40;Configuration.java&#58;426&#41;
    	at freemarker.template.Configuration.getTemplate&#40;Configuration.java&#58;398&#41;
    	at org.springframework.web.servlet.view.freemarker.FreeMarkerView.getTemplate&#40;FreeMarkerView.java&#58;168&#41;
    	at org.springframework.web.servlet.view.freemarker.FreeMarkerView.renderMergedTemplateModel&#40;FreeMarkerView.java&#58;151&#41;
    	at org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel&#40;AbstractTemplateView.java&#58;160&#41;
    	at org.springframework.web.servlet.view.AbstractView.render&#40;AbstractView.java&#58;238&#41;
    	at org.springframework.web.servlet.DispatcherServlet.render&#40;DispatcherServlet.java&#58;644&#41;
    	at org.springframework.web.servlet.DispatcherServlet.doService&#40;DispatcherServlet.java&#58;535&#41;
    	at org.springframework.web.servlet.FrameworkServlet.service&#40;FrameworkServlet.java&#58;321&#41;
    	at javax.servlet.http.HttpServlet.service&#40;HttpServlet.java&#58;103&#41;
    As you can see, the correct exception is finally thrown. However, if I restart my server with the template problem intact, it's possible to repeat this resource-loader exception bug.

    Motivation for fix? While the exceptions are working just fine if a template is already loaded, it makes debugging *new* pages while the server is running, or even old pages after a restart, very problematic. This template is trivial, however, if it were a library template with 600 lines of code, finding the bug would not be trivial. Even further, I noticed that this happens when a pages includes other templates with errors, even if the main template is syntactically correct.

    Anyway, I would really appreciate it if you guys could implement a fix since I have quite a few more templates to make :P

    Thanks,
    Ken Egervari

  • #2
    Thanks Ken. For future reference, better to log these in JIRA so they don't get lost in the forums. I've done this one..

    http://opensource.atlassian.com/proj...browse/SPR-279

    Comment


    • #3
      Re: Bug in Freemark/Spring Support

      Originally posted by egervari
      Note, you don't need this exact page to make it fail. Notice that the title attribute is missing the ending quote: "${pageTitle}

      This is an easy mistake to make however, this gives the following exception:
      side note: there are some good FTL plugins that will show such errors up in your editor/IDE. I've used the eclipse one to good effect. http://www.freemarker.org/editors.html

      Comment


      • #4
        Re: Bug in Freemark/Spring Support

        Unfortunately I'm using IDEA and it's not supported. I still think using Freemarker without syntax highlighting is more productive and produces cleaner code than velocity, so I'll stick with it either way. Glad I could help and I'll be sure to use JIRA from now on.

        Regards,
        Ken

        Comment

        Working...
        X