RFR: 8015831: Add lint check for calling overridable methods from a constructor [v7]
Maurizio Cimadamore
mcimadamore at openjdk.org
Fri Jan 13 11:11:31 UTC 2023
On Fri, 13 Jan 2023 10:58:33 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> Caring about the proper initialization of any class in the _current_ compilation unit is an explicit non-goal.
>>
>> We only care about bugs where a superclass and subclass are in separate compilation units.
>
> So, to clarify, in this case:
>
>
> import java.util.*;
>
> class B {
> final Object ref;
>
> private B(Object ref) {
> Foo.consume(this);
> this.ref = ref;
> }
> }
>
>
> Even though `this` leaks to a method clearly before it is fully initialized, we do not care because there can be no subclass involved observing this. I guess I was confused because, while subclasses are a particularly sneaky case where uninitialized values can show up, the above leak seems potentially dangerous as well - we're effectively leaking a class whose final field has not been initialized!
>
> That said, if that was discussed, and it was decided for the warning not to deal with this case, that's ok.
Perhaps my confusion might come from the name `this-escape` of the lint warning - which seems overpromising in this respect. But I looked at the description of the lint warning using `javac --help-lint` and I got this:
this-escape Warn when a constructor invokes a method that could be overriden in a subclass;
Which indeed aligns well with what this PR is doing. So that's ok.
-------------
PR: https://git.openjdk.org/jdk/pull/11874
More information about the core-libs-dev
mailing list