This is an automated email from the ASF dual-hosted git repository.
zaynt4606 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/celeborn.git
The following commit(s) were added to refs/heads/main by this push:
new cb6100c7ef [CELEBORN-2596] Fix null mapping function validation on JDK
8
cb6100c7ef is described below
commit cb6100c7efaaea88a395fdb293e9faf499c62f33
Author: F-yuyu <[email protected]>
AuthorDate: Sun Nov 22 22:44:28 2026 +0800
[CELEBORN-2596] Fix null mapping function validation on JDK 8
JIRA: https://issues.apache.org/jira/browse/CELEBORN-2596
### What changes were proposed in this pull request?
Check mappingFunction for null before the existing-key fast path in
JavaUtils.ConcurrentHashMapForJDK8.computeIfAbsent.
Add a regression test to JavaUtilsSuite.
### Why are the changes needed?
ConcurrentHashMap.computeIfAbsent requires a non-null mapping function.
The JDK 8 wrapper currently returns the existing value when the function
is null, instead of throwing NullPointerException.
### Does this PR resolve a correctness bug?
- [x] Yes
### Does this PR introduce _any_ user-facing change?
- [x] Yes
On JDK 8, a null mapping function now consistently causes
NullPointerException, including when the key already exists.
### How was this patch tested?
- Ran JavaUtilsSuite on JDK 8: 2 tests passed.
- Ran common module spotless:check.
- Ran git diff --cached --check.
Closes #4001 from F-yuyu/fix/compute-if-absent-null.
Authored-by: F-yuyu <[email protected]>
Signed-off-by: zhengtao <[email protected]>
AI-Contributed/Feature: 0/1
AI-Contributed/UT: 0/9
---
.../src/main/java/org/apache/celeborn/common/util/JavaUtils.java | 1 +
.../java/org/apache/celeborn/common/util/JavaUtilsSuite.java | 9 +++++++++
2 files changed, 10 insertions(+)
diff --git
a/common/src/main/java/org/apache/celeborn/common/util/JavaUtils.java
b/common/src/main/java/org/apache/celeborn/common/util/JavaUtils.java
index 9f1d106ce4..974de59392 100644
--- a/common/src/main/java/org/apache/celeborn/common/util/JavaUtils.java
+++ b/common/src/main/java/org/apache/celeborn/common/util/JavaUtils.java
@@ -487,6 +487,7 @@ public class JavaUtils {
@Override
public V computeIfAbsent(K key, Function<? super K, ? extends V>
mappingFunction) {
+ Preconditions.checkNotNull(mappingFunction);
V result;
if (null == (result = get(key))) {
result = super.computeIfAbsent(key, mappingFunction);
diff --git
a/common/src/test/java/org/apache/celeborn/common/util/JavaUtilsSuite.java
b/common/src/test/java/org/apache/celeborn/common/util/JavaUtilsSuite.java
index 95d48166bb..371f821123 100644
--- a/common/src/test/java/org/apache/celeborn/common/util/JavaUtilsSuite.java
+++ b/common/src/test/java/org/apache/celeborn/common/util/JavaUtilsSuite.java
@@ -17,6 +17,8 @@
package org.apache.celeborn.common.util;
+import java.util.concurrent.ConcurrentHashMap;
+
import org.junit.Assert;
import org.junit.Test;
@@ -31,4 +33,11 @@ public class JavaUtilsSuite {
Assert.assertTrue(i == inverse[arr[i]]);
}
}
+
+ @Test
+ public void testComputeIfAbsentRejectsNullMappingFunction() {
+ ConcurrentHashMap<String, String> map = JavaUtils.newConcurrentHashMap();
+ map.put("key", "value");
+ Assert.assertThrows(NullPointerException.class, () ->
map.computeIfAbsent("key", null));
+ }
}