okaywit / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Is Flushables worthwhile? #1472

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Colin, have you ever looked at the class's users? I just went through them, and 
I don't feel great about most of them. Probably a majority of them are of the 
form:

flushQuietly(stream);
stream.close(); // or closeQuietly(stream)

And I think we're confident that this flush+close pattern is unnecessary or 
even harmful, as discussed on issue 1086.

Most of the other callers are otherwise sketchy -- usually just people who 
don't want to deal with exceptions, sadly often in methods called "flush" that 
a caller might naively expect to throw if there are problems. I wouldn't feel 
bad inlining the try-catch into them. The best caller I saw was someone who was 
wrapping a ByteArrayOutputStream in an OutputStreamWriter and who then wanted 
to flush the OutputStreamWriter without dealing with IOException. (I'm not even 
sure that IOException is impossible there: Might the process of character 
encoding throw it? I supposed I'd be willing to believe that that happens in 
this particular case only due to "programmer error," but that suggests some 
kind of unchecked exception rather than the "catch and log" flushQuietly. Hmm, 
and closeQuietly (about which I also have reservations, naturally) would 
function just as well there.)

We're talking <30 callers total here.

Original issue reported on code.google.com by cpov...@google.com on 10 Jul 2013 at 12:01

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<issue id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:12

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:17

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08