API / Apache FreeMarker Interview questions
How does FreeMarker handle missing or null values differently from Java?
Java code that dereferences a null reference throws a NullPointerException immediately. FreeMarker instead represents "not present" as its own state and, by default, throws a controlled TemplateException only at the point a missing value is actually used in a way that requires a value - for example printing it or comparing it - rather than the moment it is looked up.
Templates are expected to deal with this explicitly, using the existence-test operator ?? (user.middleName??) or the default-value operator ! (user.middleName!""), instead of relying on exceptions for control flow. This design choice exists because templates are often maintained by people who are not full-time Java programmers, so FreeMarker pushes null-safety decisions into the template language itself rather than assuming every author will remember defensive Java-style null checks.
More Related questions...