RFR: 8015831: Add lint check for calling overridable methods from a constructor [v5]
Archie L. Cobbs
duke at openjdk.org
Thu Jan 12 15:29:30 UTC 2023
On Thu, 12 Jan 2023 15:10:19 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
> Interesting example - I thought you might have been referring to a case where the class being analyzed was itself an exception.
Yes - although that example doesn't compile (oops!). Just replace `catch (RuntimeException e)` with `catch (ThrownThis e)` and it should.
> Question - shouldn't we conclude that this leak when we see throw this ? E.g. what if the constructor did not have a catch (or if the catch was of a different type) ?
A thorough analysis would evaluate whether the exception was caught or not. But you're right - since we're not doing a thorough analysis, we should immediately declare a leak anytime we see `throw x` where `x` is a possible direct or indirect reference. Of course, this scenario should be unlikely in normal code.
I will add a check for that.
-------------
PR: https://git.openjdk.org/jdk/pull/11874
More information about the core-libs-dev
mailing list