Loosening requirements for super() invocation
Archie Cobbs
archie.cobbs at gmail.com
Fri Dec 30 23:47:56 UTC 2022
Hi Nathan,
On Fri, Dec 30, 2022 at 1:04 PM Nathan Reynolds <numeralnathan at gmail.com>
wrote:
> Let's say we have a constructor that calls final methods (or the class is
> final) that belong to the class and don't leak "this" (or call other final
> methods that don't leak "this"). Would this be flagged?
>
No, this would not be reported as a leak. It has to be possible that the
class being analyzed could, somehow, somewhere, someday, be subclassed in
some other compilation unit.
Also, the constructor would have to be invokable by such a subclass. So
private constructors cannot leak directly. They can leak indirectly,
however, if invoked from other constructors.
> Let's say we have a constructor that assigns all the member fields and
> then leaks "this". Would this be flagged? If so, why? This doesn't seem
> to be a leak any more since the object is fully constructed.
>
Yes, this would be flagged. The reason is that the "leak" is defined not
in terms of the class being analyzed, but in terms of some theoretical
subclass. In your example, even if the fields in the class being analyzed
are fully initialized before the leak, no fields in a subclass could be, so
from the subclass' perspective the leak still represents a threat.
-Archie
--
Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20221230/1c60c32e/attachment.htm>
More information about the amber-dev
mailing list