Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #38757

Re: it's Closeable, but I don't want to close() it yet.

Newsgroups comp.lang.java.programmer
Date 2019-02-28 11:37 -0800
References (8 earlier) <692da128-9302-41cf-a8f7-2a2a5903bf82@googlegroups.com> <3a4ed199-10a5-4ea3-882e-8d598a82dccf@googlegroups.com> <ab24ddfd-0235-4d43-8b9c-20cb8083df28@googlegroups.com> <6f5e7b36-af8f-4f1b-b7fe-f53305b8d591@googlegroups.com> <263782da-7ef6-466c-8cb3-da394bef0501@googlegroups.com>
Message-ID <662b0bed-fe24-4c60-aa3e-db09bb16d130@googlegroups.com> (permalink)
Subject Re: it's Closeable, but I don't want to close() it yet.
From Eric Douglas <e.d.programmer@gmail.com>

Show all headers | View raw


On Thursday, February 28, 2019 at 2:33:44 PM UTC-5, 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,
> 
> 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
> 
> a best guess, through some hand coded heuristics,
> that there could be a problem.
> 
> They are not theorem provers that 100% can tell
> whether something is a problem or not.
> 
> 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 wrote:
> > > Yes in the old code you had:
> > > 
> > >                          while (rs.next()) {
> > >                               r++;
> > >                          }
> > >                          rs.close();
> > > 
> > > And since rs.next() can throw an exception,
> > > it could escape a closing.
> > > 
> > > But try-resource has the ability to close
> > > as well, when the try-resource block
> > > 
> > > has an exception.
> > > 
> > > There were nice blog entries in the past
> > > from Oracle John Rose, but cant find any
> > > of them anymore. The Oracle blogs currently
> > > 
> > > look like shit, what did they do?
> > > 
> > 
> > 1) Is the confusion with Eclipse or Oracle?  I googled it and it went straight to Oracle (https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html) which even specifically mentioned my scenario, simply putting an executeQuery inside the try block, for which Eclipse complains not explicitly closing a ResultSet is a potential resource leak.
> > 

So the ResultSet shouldn't have to be closed, and Oracle's docs being correct would mean it does automatically close when you close the Statement, and if we don't want to explicitly close it, we should need a SuppressWarnings on Eclipse which should not cause any problems in executing.

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-02-27 15:51 +0000
  Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-27 08:48 -0800
    Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-02-27 19:03 +0000
      Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-27 11:09 -0800
        Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-02-28 12:20 +0000
          Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 06:19 -0800
            Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 06:52 -0800
              Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 08:24 -0800
                Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 08:34 -0800
                Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 09:00 -0800
                Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 11:12 -0800
                Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 11:26 -0800
                Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 11:33 -0800
                Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 11:37 -0800
                Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 11:41 -0800
                Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 11:48 -0800
                Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 12:51 -0800
                Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-03-01 08:47 +0000
                Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-03-01 09:31 +0000
                Re: it's Closeable, but I don't want to close() it yet. Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2019-03-03 02:01 +0100
                Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-03-04 09:38 +0000
                Re: it's Closeable, but I don't want to close() it yet. Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2019-03-04 12:26 +0100
                Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-03-05 14:34 +0000
                Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-03-05 07:34 -0800
                Re: it's Closeable, but I don't want to close() it yet. Arne Vajhøj <arne@vajhoej.dk> - 2019-03-04 13:59 -0500
  Re: it's Closeable, but I don't want to close() it yet. Marcel Mueller <news.5.maazl@spamgourmet.org> - 2019-02-28 08:30 +0100
    Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-02-28 19:10 +0000
      Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 11:34 -0800
      Re: it's Closeable, but I don't want to close() it yet. Marcel Mueller <news.5.maazl@spamgourmet.org> - 2019-02-28 22:24 +0100
        Re: it's Closeable, but I don't want to close() it yet. Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2019-02-28 23:25 +0100
          Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-03-01 09:43 +0000
  Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 12:11 -0800
    Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 13:49 -0800
      Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 13:52 -0800
        Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 13:59 -0800
          Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 16:17 -0800
  Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 12:26 -0800
  Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 13:44 -0800
  Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-03-01 07:40 -0800
    Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-03-01 08:34 -0800
  Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-03-11 06:27 -0700
    Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-03-11 07:24 -0700

csiph-web