ppkarwasz commented on code in PR #122: URL: https://github.com/apache/logging-log4j-tools/pull/122#discussion_r1593970115
########## log4j-tools-internal-freemarker-util/src/main/java/org/apache/logging/log4j/tools/internal/freemarker/util/FreeMarkerUtils.java: ########## @@ -63,28 +112,39 @@ private static Configuration createConfiguration(final Path templateDirectory) { configuration.setLogTemplateExceptions(false); configuration.setWrapUncheckedExceptions(true); configuration.setFallbackOnNullLoopVariable(false); + configuration.setSharedVariable("stop", StopMethod.INSTANCE); return configuration; } @SuppressFBWarnings("TEMPLATE_INJECTION_FREEMARKER") public static void render( final Path templateDirectory, final String templateName, final Object templateData, final Path outputFile) { try { + + // Render the template final Configuration configuration = createConfiguration(templateDirectory); final Template template = configuration.getTemplate(templateName); + final StringWriter templateOutputWriter = new StringWriter(); + template.process(templateData, templateOutputWriter); + final String templateOutput = templateOutputWriter.toString(); + + // Write the template output to the target file final Path outputFileParent = outputFile.getParent(); if (outputFileParent != null) { Files.createDirectories(outputFileParent); } try (final BufferedWriter outputFileWriter = Files.newBufferedWriter( outputFile, CHARSET, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { - template.process(templateData, outputFileWriter); + outputFileWriter.write(templateOutput); } } catch (final Exception error) { - final String message = String.format( - "failed rendering template `%s` in directory `%s` to file `%s`", - templateName, templateDirectory, outputFile); - throw new RuntimeException(message, error); + final boolean stopMethodInvoked = StopMethod.invoked(error); + if (!stopMethodInvoked) { + final String message = String.format( + "failed rendering template `%s` in directory `%s` to file `%s`", + templateName, templateDirectory, outputFile); + throw new RuntimeException(message, error); + } Review Comment: I don't think we need a `stop()` method. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org