From 67ed33112465398db44ee9555d1791776ef8f0c7 Mon Sep 17 00:00:00 2001
From: belugabehr <12578579+belugabehr@users.noreply.github.com>
Date: Sat, 14 Sep 2024 14:04:48 -0400
Subject: [PATCH] AVRO-4050: Deprecate MapUtil computeIfAbsent (#3142)
---
.../src/main/java/org/apache/avro/reflect/ReflectData.java | 3 +--
.../main/java/org/apache/avro/specific/SpecificData.java | 3 +--
.../avro/src/main/java/org/apache/avro/util/MapUtil.java | 7 ++++---
3 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java b/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
index 0c0b10478a5..95fc9598c90 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
@@ -36,7 +36,6 @@
import org.apache.avro.specific.FixedSize;
import org.apache.avro.specific.SpecificData;
import org.apache.avro.util.ClassUtils;
-import org.apache.avro.util.MapUtil;
import java.io.IOException;
import java.lang.annotation.Annotation;
@@ -839,7 +838,7 @@ public static Schema makeNullable(Schema schema) {
// Return of this class and its superclasses to serialize.
private static Field[] getCachedFields(Class> recordClass) {
- return MapUtil.computeIfAbsent(FIELDS_CACHE, recordClass, rc -> getFields(rc, true));
+ return FIELDS_CACHE.computeIfAbsent(recordClass, rc -> getFields(rc, true));
}
private static Field[] getFields(Class> recordClass, boolean excludeJava) {
diff --git a/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java b/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java
index c30616e17a3..a9dbbcbb5b6 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java
@@ -30,7 +30,6 @@
import org.apache.avro.io.DecoderFactory;
import org.apache.avro.io.EncoderFactory;
import org.apache.avro.util.ClassUtils;
-import org.apache.avro.util.MapUtil;
import org.apache.avro.util.SchemaUtil;
import org.apache.avro.util.internal.ClassValueCache;
@@ -379,7 +378,7 @@ public Class getClass(Schema schema) {
String name = schema.getFullName();
if (name == null)
return null;
- Class> c = MapUtil.computeIfAbsent(classCache, name, n -> {
+ Class> c = classCache.computeIfAbsent(name, n -> {
try {
return ClassUtils.forName(getClassLoader(), getClassName(schema));
} catch (ClassNotFoundException e) {
diff --git a/lang/java/avro/src/main/java/org/apache/avro/util/MapUtil.java b/lang/java/avro/src/main/java/org/apache/avro/util/MapUtil.java
index 1bdbfaf9a0a..394aa2b3a63 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/util/MapUtil.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/util/MapUtil.java
@@ -27,13 +27,14 @@ private MapUtil() {
}
/**
- * A temporary workaround for Java 8 specific performance issue JDK-8161372
- * .
- * This class should be removed once we drop Java 8 support.
+ * A temporary workaround for Java 8 specific performance issue JDK-8161372.
*
* @see JDK-8161372
+ * @deprecated As of JDK 1.9 this issue has been resolved.
*/
+ // TODO: Remove for 1.13.0 or later
+ @Deprecated
public static V computeIfAbsent(ConcurrentMap map, K key, Function mappingFunction) {
V value = map.get(key);
if (value != null) {