Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: Does this make sense? Date: Thu, 4 Apr 2019 11:01:59 -0400 Organization: A noiseless patient Spider Lines: 22 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 4 Apr 2019 15:02:01 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="d31579a313e0d399aa72604843672e8b"; logging-data="25414"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+VDLlYPCYnmx0Pcb+Wz1l5" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 Cancel-Lock: sha1:+lB7B2lbFOi8ADQpVo4TSttYJa4= In-Reply-To: Content-Language: en-US Xref: csiph.com comp.lang.java.programmer:38865 On 4/4/2019 10:02 AM, Eric Douglas wrote: > On Thursday, April 4, 2019 at 9:03:28 AM UTC-4, Eric Sosman wrote: >>> } finally { >>> try { >>> fos.close(); >> >> Aside: I think you need a null-test here. >> > Is a null even possible? It would have to crash in the 'new'. [...] Exactly. >> Consider try-with-resources: [...] > > Ah right, resources doesn't always work because in some cases I'm using Closeable objects instead of Autocloseable, and in some cases I'm creating the the object (in the case the java.io.File) in the same try block as the object (java.io.FileOutputStream) needing to be closed so they can't be created up front, but in this simple block that does look better. I foolishly assumed that your example code resembled the problem you actually have. I should have known better; sorry. -- esosman@comcast-dot-net.invalid Six hundred fifty-seven days to go.