The Artima Developer Community
Sponsored Link

...was wondering about that



This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


...was wondering about that

Posted by Jeff Wright on 17 Jun 1998, 9:21 PM

> One of the things in the LogFile class of this article
> that could potentially be redundant is that I call close()
> on both FileOutputStream and PrintWriter.

Yes, that caught my eye -- thanks for expanding on it!

> ...Seems like this happens from time to time, and it isn't usually
> good enough to just try it and see if it works, because even
> if it works on the environment I happen to be using, if it
> isn't well specified, then there may be other Java environments
> out there where it doesn't work. So I try to program
> defensively (here, defending against vague documentation and
> potentially against various ways the Java environment can be
> implemented by different vendors.)

Hmmm, yes, but I've also seen cases where causing close() a
second time creates an error.

[The specific example I'm thinking of was on a
java.sql.Statement. Since this is just an interface, this
behavior was just a "feature" of the particular JDBC driver.]



Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us