From 5a220a37d60876c20bed94a1bdde9b336d8187e7 Mon Sep 17 00:00:00 2001 From: Chris Povirk Date: Mon, 7 Oct 2024 11:30:51 -0400 Subject: [PATCH] Comment upon our choice for annotations for `forEach*`. --- .../classes/java/util/concurrent/ConcurrentHashMap.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java index 4315823ead1..809ae36f9b9 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java @@ -3742,6 +3742,11 @@ public void forEach(long parallelismThreshold, * @param the return type of the transformer * @since 1.8 */ + // JSpecify: We could instead use `` along with `@NonNull U`. + // Advantages to our current approach include: + // - calls out the null support in an otherwise null-hostile class + // - is consistent with the declarations for `search` and `reduce` + // - saves the user from a decision: https://github.com/jspecify/jspecify/issues/525 public void forEach(long parallelismThreshold, BiFunction transformer, Consumer action) { @@ -3909,6 +3914,7 @@ public void forEachKey(long parallelismThreshold, * @param the return type of the transformer * @since 1.8 */ + // JSpecify: See discussion on `forEach` above. public void forEachKey(long parallelismThreshold, Function transformer, Consumer action) { @@ -4096,6 +4102,7 @@ public void forEachValue(long parallelismThreshold, * @param the return type of the transformer * @since 1.8 */ + // JSpecify: See discussion on `forEach` above. public void forEachValue(long parallelismThreshold, Function transformer, Consumer action) { @@ -4280,6 +4287,7 @@ public void forEachEntry(long parallelismThreshold, * @param the return type of the transformer * @since 1.8 */ + // JSpecify: See discussion on `forEach` above. public void forEachEntry(long parallelismThreshold, Function, ? extends @Nullable U> transformer, Consumer action) {