On Fri, 13 Jan 2023 11:05:51 GMT, Maurizio Cimadamore <mcimadam...@openjdk.org> wrote:
>> 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. Something seems to be up with the lint description for this-escape - compare this: serial Warn about Serializable classes that do not have a serialVersionUID field. Also warn about other suspect declarations in Serializable and Externalizable classes and interfaces. with this: this-escape Warn when a constructor invokes a method that could be overriden in a subclass; such a method would execute before the subclass constructor completes its initialization. Indentation seems to be missing, which causes readability issues in the `--help-lint` output. ------------- PR: https://git.openjdk.org/jdk/pull/11874