-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make some type parameters inside ConcurrentHashMap
non-null.
#70
base: main
Are you sure you want to change the base?
Conversation
We already had the parameters on the class itself correct. However, we had declarations _inside_ incorrect. This PR fixes most but not all. For the most part, this PR doesn't matter: Most of these APIs are not user-visible. We had them annotated in the first place only because our CF-stub-conversion tool changes `<T>` to `<T extends @nullable Object>` everywhere inside `@NullMarked` code, without regard to whether the API is publicly visible. In fairness, this makes some sense because a non-publicly visible type can be extended by a publicly visible type, which can render the non-publicly visible type's APIs suddenly publicly visible. In fact, that happens in this very file: The package-private `CollectionView` is extended by the public `KeySetView`. Still, for _most_ of the non-visible APIs, this PR has no actual effect: It's just a simplification (by removing information about non-visible APIs, which we don't normally annotate) that happens to also make those APIs' annotations more correct. For public APIs like `KeySetView` itself, it would have made sense for the CF stubs to have `<T extends Object>`, which would have translated into plain `<T>` in our stubs. The PR's change to `<T>` could affect existing callers. I will be back with another PR that handles some other type parameters as part of actually annotating some other unannotated APIs in the class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Null-hostility looks good, just one place would benefit from some comment.
@@ -627,7 +627,7 @@ public class ConcurrentHashMap<K,V> extends AbstractMap<K,V> | |||
* are special, and contain null keys and values (but are never | |||
* exported). Otherwise, keys and vals are never null. | |||
*/ | |||
static class Node<K extends @Nullable Object,V extends @Nullable Object> implements Map.Entry<K,V> { | |||
static class Node<K,V> implements Map.Entry<K,V> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment above says Subclasses of Node with a negative hash field are special, and contain null keys and values
.
To account for these subclasses, the type parameters here should allow null.
If you did consider this, could you add a CFComment
why this is better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I hadn't. This change was just part of my mission to remove annotations from APIs that aren't visible to users. I left some new notes about that in #101. Let me know whether you have thoughts on that approach, whether this type is exposed through a subtype you missed, or if there's anything else I might be overlooking here.
We already had the parameters on the class itself correct. However, we
had declarations inside incorrect. This PR fixes most but not all.
For the most part, this PR doesn't matter: Most of these APIs are not
user-visible. We had them annotated in the first place only because our
CF-stub-conversion tool changes
<T>
to<T extends @Nullable Object>
everywhere inside
@NullMarked
code, without regard to whether the APIis publicly visible. In fairness, this makes some sense because a
non-publicly visible type can be extended by a publicly visible type,
which can render the non-publicly visible type's APIs suddenly publicly
visible. In fact, that happens in this very file: The package-private
CollectionView
is extended by the publicKeySetView
. Still, formost of the non-visible APIs, this PR has no actual effect: It's just
a simplification (by removing information about non-visible APIs, which
we don't normally annotate) that happens to also make those APIs'
annotations more correct.
For public APIs like
KeySetView
itself, it would have made sense forthe CF stubs to have
<T extends Object>
, which would have translatedinto plain
<T>
in our stubs. The PR's change to<T>
could affectexisting callers.
I will be back with another PR that handles some other type parameters
as part of actually annotating some other unannotated APIs in the class.