click-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrey Rybin (JIRA)" <j...@apache.org>
Subject [jira] Created: (CLK-613) Flush & close inconsistency
Date Mon, 18 Jan 2010 08:36:56 GMT
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.


Mime
View raw message