On Sat, 10 May 2025 20:28:39 GMT, Vicente Romero <vrom...@openjdk.org> wrote:

>> This PR is defining a new internal annotation, 
>> `@jdk.internal.RequiresIdentity`, with target types PARAMETER and 
>> TYPE_PARAMETER. The @RequiresIdentity annotation expresses the expectation 
>> that an argument to a given method or constructor parameter will be an 
>> object with a unique identity, not an instance of a value-based class; or 
>> that the type argument to a given type parameter will not be a value-based 
>> class type.
>> 
>> For more details please refer to the complete description in the 
>> corresponding JIRA entry [1]
>> 
>> TIA
>> 
>> [1] https://bugs.openjdk.org/browse/JDK-8354556
>
> Vicente Romero has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Update src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java
>   
>   Co-authored-by: Chen Liang <li...@openjdk.org>

I'm coming here from "far away" and am not familiar with all the work leading
up to this proposal, so maybe there's some rationale that I don't know about.
(I did look, but didn't find anything other than this draft JEP:
https://openjdk.org/jeps/8340476. And that doesn't really deal with the issue
I discuss below.)

Keeping that in mind, I'm surprised by some parts of this change.  Specifically

2) Apply the annotation to the following:
- The referent parameter of all constructors in classes PhantomReference, 
SoftReference, and WeakReference
...
 - The type parameter T of Reference, PhantomReference, SoftReference, 
WeakReference, and ReferenceQueue 

I wonder why it is not sufficient to apply the annotation to the type
parameter T of Reference, and leave it at that?

The type parameter of the subclasses is passed as the type parameter to
Reference in the `extends` clause. I would expect if the type parameter for a
subclass didn't satisfy the annotation that would be noticed there. Indeed, if
that isn't the case then many uses of Reference types won't benefit from this
annotation, since they are using classes derived from one of those subclasses
and won't have this internal annotation. That would significantly limit the
utility of this annotation in this area.

Similarly, I wonder why the constructors need the annotation. And why don't
the return type of `get` or the argument for `Reference::refersTo` need it?
(Maybe because those values can be null? But there's nothing that prevents
passing null to one of the constructors. It's not very useful to do so, but
not forbidden.  I've even seen a use-case for doing so.)

-------------

PR Comment: https://git.openjdk.org/jdk/pull/24746#issuecomment-2870055928

Reply via email to