Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-117030

The Liferay Freemarker custom object wrapper throws a NonHashException when evaluating a StaticUtil String expression inside a Freemarker template

    Details

      Description

      Reproduction Steps:

      1. Setup a plain Liferay bundle 
      2. Startup the server and login to the portal
      3. Create a new structure and configure any field in it
      4. Create a new template based on the above structure and add following lines of code in the template:

      <#assign serviceContext = staticUtil["com.liferay.portal.kernel.service.ServiceContextThreadLocal"].getServiceContext()>
      <#assign themeDisplay = serviceContext.getThemeDisplay() />
      <#assign themeId = themeDisplay.getThemeId().toUpperCase()/>
      ${themeId}
      

      5. Go to Control Panel > System Settings > Platform > Template Engines > Freemarker Engine , and delete the configured restriction for the variable "staticUtil".
      6. Create a new web content based on the structure/template created earlier and display it on a page via a WCD portlet.
      7. Assert that the content doesn't render and the following Freemarker error is seen on the page:

      For "." left-hand operand: Expected a hash, but this has evaluated to a string (wrapper: f.t.SimpleScalar):
      ==> themeDisplay.getThemeId()
      

      The error with Fix Pack 6 is reproducible on 7.2.x @ f71caa4a2295eeb04f86d013c91884a36fd47f9561855bbe3496ae844e65add9 and master @ 7456baa3c43b0b99045a078309a57fa9e38bd3e8cb72be25406a7a8c168c9adf

      When facing the error on Fix Pack 6, using:

      <#assign themeId = themeDisplay.getThemeId()?upper_case>

      as per https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_upper_case will work.
      Also Fix Pack 5 is working without issues.

        Attachments

          Activity

            People

            Assignee:
            peter.petrekanics Peter Petrekanics
            Reporter:
            peter.petrekanics Peter Petrekanics
            Participants of an Issue:
            Recent user:
            Tibor Lipusz
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Days since last comment:
              1 year, 9 weeks, 6 days ago

                Packages

                Version Package