You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Zhang, Huxing" <hu...@intel.com> on 2010/10/25 04:47:58 UTC
[io] missing java.io.PrintWriter.close() in
org.apache.commons.io.testtools.FileBasedTestCase.checkWrite()
Dear Apache Commons IO developers,
I found there might be a close method missing in the source code of test cases, which may be an issue.
No patch seems to be applied till revision 1026932.
How do you guys think?
The original code here is:
In io/trunk/src/test/java/org/apache/commons/io/testtools/FileBasedTestCase.java
Line 203-223 (revision 1026932)
protected void checkWrite(OutputStream output) throws Exception {
try {
new java.io.PrintStream(output).write(0);
} catch (Throwable t) {
throw new AssertionFailedError(
"The copy() method closed the stream "
+ "when it shouldn't have. "
+ t.getMessage());
}
}
protected void checkWrite(Writer output) throws Exception {
try {
new java.io.PrintWriter(output).write('a');
} catch (Throwable t) {
throw new AssertionFailedError(
"The copy() method closed the stream "
+ "when it shouldn't have. "
+ t.getMessage());
}
}
The java.io.PrintWriter is initialized without being closed after use. So does the java.io.PrintStream instance.
Thanks &Best regards,
Huxing
Re: [io] missing java.io.PrintWriter.close() in org.apache.commons.io.testtools.FileBasedTestCase.checkWrite()
Posted by Niall Pemberton <ni...@gmail.com>.
On Tue, Oct 26, 2010 at 6:13 AM, Julien Aymé <ju...@gmail.com> wrote:
> Hi Huxing,
>
> since the PrintStream/PrintWriter are built around an existing (open)
> OutputStream/Writer: the parameter passed to the method,
> it is the responsibility of the caller to close the OutputStream/Writer.
>
> Thus, there is no need to close the PrintStream/PrintWriter (they
> would close the underlying OutputStream/Writer, which is not what
> would be expected when the method is called).
Thanks Julien for responding to this.
I would also add that my main question would be (sorry haven't had
time to look at where this is used within IO's tests) "does this
invalidate or cause IO's tests to fail?"
Niall
> Regards,
> Julien
>
> 2010/10/25 Zhang, Huxing <hu...@intel.com>:
>> Dear Apache Commons IO developers,
>> I found there might be a close method missing in the source code of test cases, which may be an issue.
>> No patch seems to be applied till revision 1026932.
>> How do you guys think?
>>
>> The original code here is:
>> In io/trunk/src/test/java/org/apache/commons/io/testtools/FileBasedTestCase.java
>> Line 203-223 (revision 1026932)
>>
>> protected void checkWrite(OutputStream output) throws Exception {
>> try {
>> new java.io.PrintStream(output).write(0);
>> } catch (Throwable t) {
>> throw new AssertionFailedError(
>> "The copy() method closed the stream "
>> + "when it shouldn't have. "
>> + t.getMessage());
>> }
>> }
>>
>> protected void checkWrite(Writer output) throws Exception {
>> try {
>> new java.io.PrintWriter(output).write('a');
>> } catch (Throwable t) {
>> throw new AssertionFailedError(
>> "The copy() method closed the stream "
>> + "when it shouldn't have. "
>> + t.getMessage());
>> }
>> }
>>
>> The java.io.PrintWriter is initialized without being closed after use. So does the java.io.PrintStream instance.
>>
>> Thanks &Best regards,
>> Huxing
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [io] missing java.io.PrintWriter.close() in org.apache.commons.io.testtools.FileBasedTestCase.checkWrite()
Posted by Julien Aymé <ju...@gmail.com>.
Hi Huxing,
since the PrintStream/PrintWriter are built around an existing (open)
OutputStream/Writer: the parameter passed to the method,
it is the responsibility of the caller to close the OutputStream/Writer.
Thus, there is no need to close the PrintStream/PrintWriter (they
would close the underlying OutputStream/Writer, which is not what
would be expected when the method is called).
Regards,
Julien
2010/10/25 Zhang, Huxing <hu...@intel.com>:
> Dear Apache Commons IO developers,
> I found there might be a close method missing in the source code of test cases, which may be an issue.
> No patch seems to be applied till revision 1026932.
> How do you guys think?
>
> The original code here is:
> In io/trunk/src/test/java/org/apache/commons/io/testtools/FileBasedTestCase.java
> Line 203-223 (revision 1026932)
>
> protected void checkWrite(OutputStream output) throws Exception {
> try {
> new java.io.PrintStream(output).write(0);
> } catch (Throwable t) {
> throw new AssertionFailedError(
> "The copy() method closed the stream "
> + "when it shouldn't have. "
> + t.getMessage());
> }
> }
>
> protected void checkWrite(Writer output) throws Exception {
> try {
> new java.io.PrintWriter(output).write('a');
> } catch (Throwable t) {
> throw new AssertionFailedError(
> "The copy() method closed the stream "
> + "when it shouldn't have. "
> + t.getMessage());
> }
> }
>
> The java.io.PrintWriter is initialized without being closed after use. So does the java.io.PrintStream instance.
>
> Thanks &Best regards,
> Huxing
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org