Flush & close inconsistency
---------------------------
Key: CLK-613
URL: https://issues.apache.org/jira/browse/CLK-613
Project: Click
Issue Type: Bug
Affects Versions: 2.1.0 RC1
Reporter: Andrey Rybin
1) ClickUtils.encode has bug:
oos = new ObjectOutputStream(gos);
oos.writeObject(object);
oos.close();// <-- here must be .flush()
} finally {
close(oos);
2) My suggestion is to add one new method to ClickUtils
public static void flushAndClose (Closeable someStreamOrWriter) { //@Nullable
if (someStreamOrWriter != null) {
if (someStreamOrWriter instanceof Flushable) {//can be closed already -
so IOException is ok
try { ((Flushable) someStreamOrWriter).flush(); } catch (Throwable
ignore) {}
}//if can flush
try {
someStreamOrWriter.close();
} catch (Throwable e) {
log.debug("flushAndClose: can't close "+ someStreamOrWriter, e);
}
}//i
}//flushAndClose
and use it (as coding standard) for OutputStreams and Writers.
3) All occurrences of "safe" - "try { x.close() } catch.." - and - try {
w.flush(); } catch try { w.close() - should be replaced with
ClickUtils.close(x);
ClickUtils.flushAndClose(w);
Here my ".close coding standard violation" list:
CompressionServletResponseWrapper
finishResponse
VelocityTemplateService
getInitProperties
ErrorReport
getRenderedSource
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.