From 60c7cdf7103c5c5350a6e1a62c00e339dfc9d54d Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Fri, 4 Nov 2011 11:12:32 +0100 Subject: [PATCH] Avoid error log from velocity if no custom e-mail template exists The code to determine the template that should be used for sending an e-mail notification first tries to load a custom e-mail template and only if a custom template cannot be found it falls back to the default template. The problem is that trying to load a non-existing custom e-mail template results in an error log, e.g.: ERROR velocity : ResourceManager : unable to find resource 'ChangeSubject.vm' in any resource loader. The new code checks whether a custom template exists before trying to load it. Change-Id: Icec3067792f1d2102a11bec1356844280b9e72f9 Signed-off-by: Edwin Kempin --- .../java/com/google/gerrit/server/mail/OutgoingEmail.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/mail/OutgoingEmail.java b/gerrit-server/src/main/java/com/google/gerrit/server/mail/OutgoingEmail.java index 9f57f19e12..ce788cf3e9 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/mail/OutgoingEmail.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/mail/OutgoingEmail.java @@ -374,13 +374,10 @@ public abstract class OutgoingEmail { protected String velocifyFile(String name) throws EmailException { try { RuntimeInstance runtime = args.velocityRuntime; - Template template; - try { - template = runtime.getTemplate(name, "UTF-8"); - } catch (org.apache.velocity.exception.ResourceNotFoundException notFound) { + if (runtime.getLoaderNameForResource(name) == null) { name = "com/google/gerrit/server/mail/" + name; - template = runtime.getTemplate(name, "UTF-8"); } + Template template = runtime.getTemplate(name, "UTF-8"); StringWriter w = new StringWriter(); template.merge(velocityContext, w); return w.toString();