Legacy Knowledge Base
Published Jul. 2, 2025

InvalidReferenceException when rendering an article template

Written By

Roberto Díaz

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Issue

  • Adding a new field in an existing estructure produces an InvalidReferenceException in articles unless you update them if you try to render this field in a template:
    freemarker.core.InvalidReferenceException: [... Exception message was already printed; see it above ...]
    at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:134)
    at freemarker.core.UnexpectedTypeException.newDescriptionBuilder(UnexpectedTypeException.java:85)
    at freemarker.core.UnexpectedTypeException.<init>(UnexpectedTypeException.java:48)
    at freemarker.core.NonHashException.<init>(NonHashException.java:49)
    at freemarker.core.Dot._eval(Dot.java:48)
    at freemarker.core.Expression.eval(Expression.java:101)
    at freemarker.core.MethodCall._eval(MethodCall.java:55)
    at freemarker.core.Expression.eval(Expression.java:101)
    at freemarker.core.Assignment.accept(Assignment.java:134)
    at freemarker.core.Environment.visit(Environment.java:331)
    at freemarker.core.Environment.visit(Environment.java:337)
    at freemarker.core.Environment.visit(Environment.java:337)
    at freemarker.core.Environment.process(Environment.java:310)
    at freemarker.template.Template.process(Template.java:383)
    at com.liferay.portal.template.freemarker.internal.FreeMarkerTemplate.processTemplate(FreeMarkerTemplate.java:154)
    at com.liferay.portal.template.BaseTemplate.processTemplate(BaseTemplate.java:163)
    at com.liferay.journal.internal.transformer.JournalTransformer.doTransform(JournalTransformer.java:367)
    at com.liferay.journal.internal.transformer.JournalTransformer.transform(JournalTransformer.java:103)

Environment

  • Liferay DXP 7.0
  • Liferay DXP 7.1
  • Liferay DXP 7.2
  • Liferay DXP 7.3
  • Liferay DXP 7.4

Resolution

  • The problem here is that the structure has a field but the article content does not, so if you try to render the structure the field will be null and it will throw a null pointer exception when the getData() method is used.
  • This NPE will be shown as the InvalidReferenceException by the template engine.
  • The solution is to add a null check in the template for this kind of fields to avoid rendering them if they are null.
  • Instead of rendering it like
    <#assign field = field.getData()>
    you could use
    <#if field?? && field.getData()?? >
        <#assign field = field.getData()>
    <#else>
    <#assign field = "">
    </#if>
Did this article resolve your issue ?

Legacy Knowledge Base