- template.render(writer);
- StringBucket bucket = new StringBucket(writer.toString(), utf8Charset);
- return new ManifestElement(name, bucket, contentType, bucket.size());
+ StringBucket bucket = null;
+ try {
+ template.render(writer);
+ bucket = new StringBucket(writer.toString(), utf8Charset);
+ return new ManifestElement(name, bucket, contentType, bucket.size());
+ } catch (TemplateException te1) {
+ logger.log(Level.SEVERE, "Could not render template “" + templateName + "”!", te1);
+ return null;
+ } finally {
+ Closer.close(writer);
+ if (bucket != null) {
+ bucket.free();
+ }
+ }