X-Received: by 2002:ac8:3826:: with SMTP id q35mr609307qtb.31.1551382875240; Thu, 28 Feb 2019 11:41:15 -0800 (PST) X-Received: by 2002:a81:9bd3:: with SMTP id s202mr611541ywg.76.1551382875051; Thu, 28 Feb 2019 11:41:15 -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!m21no5209050qta.0!news-out.google.com!y15ni2305qta.0!nntp.google.com!m21no5209044qta.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.java.programmer Date: Thu, 28 Feb 2019 11:41:14 -0800 (PST) In-Reply-To: <263782da-7ef6-466c-8cb3-da394bef0501@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=84.74.101.34; posting-account=UjEXBwoAAAAOk5fiB8WdHvZddFg9nJ9r NNTP-Posting-Host: 84.74.101.34 References: <709a1f3b-fc99-4bd0-a8b8-866092bb7ae9@googlegroups.com> <8e1597a2-5c18-4fd1-83a4-7667e4d11e77@googlegroups.com> <23a8128b-5c54-45ba-bfd0-2f7dda078517@googlegroups.com> <692da128-9302-41cf-a8f7-2a2a5903bf82@googlegroups.com> <3a4ed199-10a5-4ea3-882e-8d598a82dccf@googlegroups.com> <6f5e7b36-af8f-4f1b-b7fe-f53305b8d591@googlegroups.com> <263782da-7ef6-466c-8cb3-da394bef0501@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: it's Closeable, but I don't want to close() it yet. From: bursejan@gmail.com Injection-Date: Thu, 28 Feb 2019 19:41:15 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Lines: 70 Xref: csiph.com comp.lang.java.programmer:38758 Mostlikely ResultSet is anyway auto closing in the sense that when you have reached the last row, it will anyway close. Not sure about that. But it should be automatically closed when you read=20 the next page via the same prepared statement,=20 since the documentation says: "A ResultSet object is automatically closed when=20 the Statement object that generated it is closed,=20 re-executed, or used to retrieve the next result=20 from a sequence of multiple results."=20 https://docs.oracle.com/javase/7/docs/api/java/sql/ResultSet.html On Thursday, February 28, 2019 at 8:33:44 PM UTC+1, burs...@gmail.com wrote= : > Since Eclipse says "potential", it is not sure about its > judgement. Probably it uses some heuristics to find > close leaking, and in your case, >=20 > it produces maybe a false positive. All these checks > that different IDEs offer work by inspecting a small > part of your code and work by producing >=20 > a best guess, through some hand coded heuristics, > that there could be a problem. >=20 > They are not theorem provers that 100% can tell > whether something is a problem or not. >=20 > On Thursday, February 28, 2019 at 8:26:34 PM UTC+1, Eric Douglas wrote: > > On Thursday, February 28, 2019 at 2:12:55 PM UTC-5, burs...@gmail.com w= rote: > > > Yes in the old code you had: > > >=20 > > > while (rs.next()) { > > > r++; > > > } > > > rs.close(); > > >=20 > > > And since rs.next() can throw an exception, > > > it could escape a closing. > > >=20 > > > But try-resource has the ability to close > > > as well, when the try-resource block > > >=20 > > > has an exception. > > >=20 > > > There were nice blog entries in the past > > > from Oracle John Rose, but cant find any > > > of them anymore. The Oracle blogs currently > > >=20 > > > look like shit, what did they do? > > >=20 > >=20 > > 1) Is the confusion with Eclipse or Oracle? I googled it and it went s= traight to Oracle (https://docs.oracle.com/javase/tutorial/essential/except= ions/tryResourceClose.html) which even specifically mentioned my scenario, = simply putting an executeQuery inside the try block, for which Eclipse comp= lains not explicitly closing a ResultSet is a potential resource leak. > >=20 > > 2) I don't see the scenario in the Oracle doc for re-using a variable. = Should I be able to close a RecordSet and call executeQuery again to that = same variable in that same method? > >=20 > > 3) How should we close a resource such as InputStream or OutputStream? = I had written the API in such a way if I'm passing them into a method to b= e read once, that method is closing them. We should never close them while= reading/writing them and expect them to get closed after the call by the m= ethod that opened them?