Be more robust about closing template Reader.
Also some tidying: we don't like tabs or trailing whitespace.
This commit is contained in:
@@ -741,16 +741,22 @@ public class Mustache
|
|||||||
// we compile our template lazily to avoid infinie recursion if a template includes
|
// we compile our template lazily to avoid infinie recursion if a template includes
|
||||||
// itself (see issue #13)
|
// itself (see issue #13)
|
||||||
if (_template == null) {
|
if (_template == null) {
|
||||||
|
Reader tin = null;
|
||||||
try {
|
try {
|
||||||
Reader t = _comp.loader.getTemplate(_name);
|
tin = _comp.loader.getTemplate(_name);
|
||||||
_template = _comp.compile(t);
|
_template = _comp.compile(tin);
|
||||||
t.close();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (e instanceof RuntimeException) {
|
if (e instanceof RuntimeException) {
|
||||||
throw (RuntimeException)e;
|
throw (RuntimeException)e;
|
||||||
} else {
|
} else {
|
||||||
throw new MustacheException("Unable to load template: " + _name, e);
|
throw new MustacheException("Unable to load template: " + _name, e);
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
if (tin != null) try {
|
||||||
|
tin.close();
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
throw new RuntimeException(ioe);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// we must take care to preserve our context rather than creating a new one, which
|
// we must take care to preserve our context rather than creating a new one, which
|
||||||
|
|||||||
Reference in New Issue
Block a user