X-Received: by 2002:a0c:956c:: with SMTP id m41mr1862118qvm.60.1551800078585; Tue, 05 Mar 2019 07:34:38 -0800 (PST) X-Received: by 2002:a25:ab2f:: with SMTP id u44mr2604310ybi.377.1551800078244; Tue, 05 Mar 2019 07:34:38 -0800 (PST) Path: csiph.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!m21no9336087qta.0!news-out.google.com!y15ni5027qta.0!nntp.google.com!m21no9336082qta.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.java.programmer Date: Tue, 5 Mar 2019 07:34:37 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=50.78.95.177; posting-account=2czF5goAAAD4GBMPIGV4KcD2K4PhoB_H NNTP-Posting-Host: 50.78.95.177 References: <709a1f3b-fc99-4bd0-a8b8-866092bb7ae9@googlegroups.com> <8e1597a2-5c18-4fd1-83a4-7667e4d11e77@googlegroups.com> <23a8128b-5c54-45ba-bfd0-2f7dda078517@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <90b7548b-5969-49e1-8bad-45db596504aa@googlegroups.com> Subject: Re: it's Closeable, but I don't want to close() it yet. From: Eric Douglas Injection-Date: Tue, 05 Mar 2019 15:34:38 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Lines: 21 Xref: csiph.com comp.lang.java.programmer:38797 On Tuesday, March 5, 2019 at 9:34:40 AM UTC-5, Andreas Leitgeb wrote: > I added a third helper (starting as a copy of helper2) which receives > an Entity-typed parameter instead of the Context, and its first line > changed to Entity ent =3D e; then I still get the warning, but if the > initialization of entImpl is also changed to init from "e" rather than > from "ent", then the warning disappears. That is curious. Eclipse complains about Closeable variables not getting c= losed if they're declared locally, not if they're declared in method parame= ters since it expects the caller to close them...and you can cast a method = parameter that is not Closeable into a new variable that is, but if you ass= ign that to another local variable first it complains, even though both loc= al declarations are just pointers to the method parameter... Short answer was don't let your class implement Closeable unless it's suppo= sed to be closed every time it's accessed. If it's supposed to stay open t= o be closed by one cleanup process which casts it to a Closeable subclass t= hat subclass should only be used by the cleanup. It would be safer to use AutoCloseable so it's guaranteed to be closed, by = the process that opened it. Then have all new instances created by and sha= red out of a factory class?