Skip to content

Commit 5a220a3

Browse files
committed
Comment upon our choice for annotations for forEach*.
1 parent c845d13 commit 5a220a3

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java

+8
Original file line numberDiff line numberDiff line change
@@ -3742,6 +3742,11 @@ public void forEach(long parallelismThreshold,
37423742
* @param <U> the return type of the transformer
37433743
* @since 1.8
37443744
*/
3745+
// JSpecify: We could instead use `<U extends @Nullable Object>` along with `@NonNull U`.
3746+
// Advantages to our current approach include:
3747+
// - calls out the null support in an otherwise null-hostile class
3748+
// - is consistent with the declarations for `search` and `reduce`
3749+
// - saves the user from a decision: https://github.com/jspecify/jspecify/issues/525
37453750
public <U> void forEach(long parallelismThreshold,
37463751
BiFunction<? super K, ? super V, ? extends @Nullable U> transformer,
37473752
Consumer<? super U> action) {
@@ -3909,6 +3914,7 @@ public void forEachKey(long parallelismThreshold,
39093914
* @param <U> the return type of the transformer
39103915
* @since 1.8
39113916
*/
3917+
// JSpecify: See discussion on `forEach` above.
39123918
public <U> void forEachKey(long parallelismThreshold,
39133919
Function<? super K, ? extends @Nullable U> transformer,
39143920
Consumer<? super U> action) {
@@ -4096,6 +4102,7 @@ public void forEachValue(long parallelismThreshold,
40964102
* @param <U> the return type of the transformer
40974103
* @since 1.8
40984104
*/
4105+
// JSpecify: See discussion on `forEach` above.
40994106
public <U> void forEachValue(long parallelismThreshold,
41004107
Function<? super V, ? extends @Nullable U> transformer,
41014108
Consumer<? super U> action) {
@@ -4280,6 +4287,7 @@ public void forEachEntry(long parallelismThreshold,
42804287
* @param <U> the return type of the transformer
42814288
* @since 1.8
42824289
*/
4290+
// JSpecify: See discussion on `forEach` above.
42834291
public <U> void forEachEntry(long parallelismThreshold,
42844292
Function<Map.Entry<K,V>, ? extends @Nullable U> transformer,
42854293
Consumer<? super U> action) {

0 commit comments

Comments
 (0)