API / Apache Velocity Interview questions
How does Velocity resolve a variable reference at render time?
When the renderer hits a reference node in the parsed template AST, it walks a defined resolution path rather than doing a single lookup.
The lookup for the base key goes straight to the Context implementation (usually VelocityContext). Everything after the first dot, like .name, is resolved through Velocity's introspection layer (the Uberspector), which tries a getter method first (getName()), then a public field, following standard JavaBean conventions.
If any step in that chain fails, the base key is missing, the getter throws, or the property doesn't exist, the default lenient behavior kicks in and the reference is written to output literally rather than aborting the render.
More Related questions...