API / Apache Velocity Interview questions
How do you troubleshoot a "parse error" in a VTL template?
Velocity's ParseErrorException reports the template name, line, and column where the parser got stuck, which is the first place to look. Most parse errors trace back to one of a small set of causes.
- Unclosed block directive — a missing
#endafter #if, #foreach, or #macro. - Mismatched quotes — a string literal missing its closing quote, or mixing single/double quotes incorrectly.
- Invalid characters in a reference name — VTL identifiers must start with a letter and can't contain most punctuation.
- Directive used outside a valid context — like #break outside any loop or macro.
Enabling Velocity's logging (via runtime.log.instance or a SLF4J binding) surfaces the exact exception with its line/column, and running the specific template in isolation with a minimal context, rather than the full application, quickly narrows down which directive is malformed.
More Related questions...