class VelocityNonStrictHelper {

    private String evaluate(Reader templateReader, Map<String, Object> variables, String logTag, boolean strict)
    {
        /*  Get and initialize a velocity engine  */
        VelocityEngine velocityEngine = new VelocityEngine();
        velocityEngine.setProperty(RuntimeConstants.RUNTIME_REFERENCES_STRICT, strict);
        velocityEngine.setProperty(RuntimeConstants.UBERSPECT_CLASSNAME, SecureUberspector.class.getName());
        velocityEngine.init();

        VelocityContext velocityContext = new VelocityContext(variables);
        StringWriter writer = new StringWriter();
        if (!velocityEngine.evaluate(velocityContext, writer, logTag, templateReader))
        {
            // Although the velocityEngine.evaluate method's Javadoc states that it will return false to indicate a failure when the template couldn't be
            // processed and to see the Velocity log messages for more details, upon examining the method's implementation, it doesn't look like
            // it will ever return false. Instead, other RuntimeExceptions will be thrown (e.g. ParseErrorException).
            // Nonetheless, we'll leave this checking here to honor the method's contract in case the implementation changes in the future.
            // Having said that, there will be no way to JUnit test this flow.
            throw new IllegalStateException("Error evaluating velocity template. See velocity log message for more details.");
        }
        return writer.toString();
    }

}