API / Apache Velocity Interview questions
What is strict reference mode in Velocity, and how does it differ from the default lenient mode?
By setting runtime.references.strict to true, Velocity switches from silently printing undefined references as literal text to throwing a MethodInvocationException (or similar) as soon as an undefined variable or a failed method/property lookup is hit.
| Aspect | Lenient (default) | Strict |
| Undefined reference | Prints literal text, e.g. $foo | Throws an exception |
| Typos / renamed getters | Fail silently, easy to miss | Fail loudly during testing |
| Best suited for | Production resilience, bulk generation jobs | Development and CI, catching mistakes early |
engine.setProperty("runtime.references.strict", "true");
A common pattern is to run strict mode in development and integration tests, where a broken reference should fail a build, while keeping lenient mode in production, where you'd rather show a slightly broken page than a hard 500 error from one bad record.
More Related questions...