API / Apache Velocity Interview questions
How does Velocity handle null values inside #if conditions and references?
A null reference is treated as falsy under "Velocity truth," so #if($user.middleName) evaluates to false whether middleName is null, an empty string, or was never set, without throwing a NullPointerException.
#if($user.middleName) Middle name: $user.middleName #end
When a null value is printed directly rather than tested in a condition, Velocity's default behavior (in lenient mode) renders it as the literal string "null" if the reference resolved successfully but the value itself is null, which is a subtly different case from an undefined reference (which prints the reference name instead). Combining $! with a null-valued reference still suppresses output, since quiet reference notation treats both "undefined" and "resolves to null" the same way.
More Related questions...