Repository navigation
Conversation
(noticed during #179) Interesting cases: - I notice that `removeAll` can handle null elements if it falls into the `c instanceof Set<?> && c.size() > t.length` case or the `map.table` null case. I'm not sure whether to consider that enough for the parameter's type argument to be nullable or not. Is it fundamentally different from noticing how the method can handle an argument with a nullable element type _if that argument happens to contain no elements_? (By _that_ logic, even `ImmutableList.copyOf` should use a nullable type argument for its parameter!) I ended up moving to including a non-null bound on the wildcard. - `contains` and `remove` are defined in the superclass `CollectionView`, and each can handle `null` in at least one package-private subclasses, despite the blanket `@throws` clause in the documentation. But they do throw for `KeySetView`, which is the only user-visible type. So I went with a non-null type there, as well. - Instead of declaring the type parameter of `KeySetView` as `V extends @nullable Object`, we could leave it as `V` but declare the obscure `getMappedValue()` as returning `@Nullable V`. (I see no calls to that method in our depot, and I don't think I knew it existed before today.) I decided to go with the principled `V extends @nullable Object` approach, which might require a handful of updates in Google's Kotlin code (to declare `ConcurrentHashMap.KeySetView<K, V?>` instead of `ConcurrentHashMap.KeySetView<K, V>`, but they should probably use `Set<K>` instead, anyway).
|
(I have another PR in the works, but that's more of an "in a few weeks" timeline. This one should be all for today, at the very least :)) |
My overnight testing ran into a problem [edit: unrelated to my actual changes], so I don't have full results yet. But based on a quick manual search, I'm not sure we'll even need to update any users of So I continue to like the proposed version in this CL. (Plus, I'm nowadays always excited when I find a good use case for |
|
I'm a bit slammed for the next couple of days. @wmdietl do you have time to look at this one? |
|
(Certainly do feel welcome to review, but zero rush!) |
(noticed during #179)
Interesting cases:
removeAllcan handle null elements if it falls into thec instanceof Set<?> && c.size() > t.lengthcase or themap.tablenull case. I'm not sure whether to consider that enough for the parameter's type argument to be nullable or not. Is it fundamentally different from noticing how the method can handle an argument with a nullable element type if that argument happens to contain no elements? (By that logic, evenImmutableList.copyOfshould use a nullable type argument for its parameter!) I ended up moving to including a non-null bound on the wildcard.containsandremoveare defined in the superclassCollectionView, and each can handlenullin at least one package-private subclasses, despite the blanket@throwsclause in the documentation. But they do throw forKeySetView, which is the only user-visible type. So I went with a non-null type there, as well.KeySetViewasV extends @Nullable Object, we could leave it asVbut declare the obscuregetMappedValue()as returning@Nullable V. (I see no calls to that method in our depot, and I don't think I knew it existed before today.) I decided to go with the principledV extends @Nullable Objectapproach, which might require a handful of updates in Google's Kotlin code (to declareConcurrentHashMap.KeySetView<K, V?>instead ofConcurrentHashMap.KeySetView<K, V>, but they should probably useSet<K>instead, anyway).