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


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

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

From Andreas Leitgeb <avl@logic.at>
Newsgroups comp.lang.java.programmer
Subject Re: it's Closeable, but I don't want to close() it yet.
Date 2019-03-05 14:34 +0000
Organization A noiseless patient Spider
Message-ID <slrnq7t27o.cfl.avl@logic.at> (permalink)
References (7 earlier) <f71c1d05-cc27-4ecb-bea0-c32f03cd698e@googlegroups.com> <slrnq7hv02.cfl.avl@logic.at> <q5f90n$nli$1@dont-email.me> <slrnq7psg5.cfl.avl@logic.at> <q5j225$6o3$1@dont-email.me>

Show all headers | View raw


Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> wrote:
> On 2019-03-04 10:38, Andreas Leitgeb wrote:
>> Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> wrote:
>>> On 2019-03-01 10:31, Andreas Leitgeb wrote:
>>>>    private static void helper2(Context ctx) {
>>>>        Entity ent = ctx.getEnt();
>>>>        if (ent instanceof EntityImpl) {
>>>>           // the following line gets tagged by eclipse:
>>>>           //  "Resource leak: 'entImp' is never closed"
>>>>           EntityImpl entImp = (EntityImpl)ent;
>>>>           entImp.b();
>>>>        }
>>>>     }
>>>> }
>>> Colour me agnostic, but that warning seems absolutely ridiculous to me.
>>> Are you sure that's the cause of it? Could EntityImpl#b perhaps be doing
>>> something funky?
>> I did provide the implementation of b() in my posting. It was an SSCCE.
>> (Reminder: It was empty, except for a /* ... */ comment.)
> Hmmm.
> For the record, IntelliJ fires off no such warning (then again, its
> inspection profiles are configurable).
> Do you also get the warning if you used a try-with-resources in the main
> of your SSCCE?

Yes. I tried it. The warning is only relevant to helper2, and it
doesn't matter what main(String[] args) looks like.

In case you want to see what it looks like in eclipse:
  https://pasteboard.co/I41cNSn.png   (*)


For what it's worth:

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 = 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.

 private static void helper3(Entity e) {
    Entity ent = e;
    if (ent instanceof EntityImpl) {
       // the following line gets tagged by eclipse:
       //   "Resource leak: 'entImp' is never closed"
       EntityImpl entImp = (EntityImpl)ent;

       // replacing above line to this lets warning disappear
       //EntityImpl entImp = (EntityImpl)e;

       entImp.b();
    }
 }

Apparently, eclipse's heuristic does take the immediate initialisation
source of the Closeable ref into account.

(*): got this site from google. Reviewing the link didn't work for me,
    but maybe does for others. if it doesn't work, and you're curious,
    feel free to suggest an alternative image upload site.
    

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