From ae26c3e02d99389e92fa5173fa7b9ff4c12207f4 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 1 Sep 2024 21:08:55 -0400 Subject: [PATCH 1/2] AVRO-4050: Deprecate MapUtil computeIfAbsent --- .../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 | 6 +++--- 3 files changed, 5 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..23e4ea9c43e 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,13 @@ 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. */ + @Deprecated public static V computeIfAbsent(ConcurrentMap map, K key, Function mappingFunction) { V value = map.get(key); if (value != null) { From 4cf5fb7418638832d8841d132a5d6b0b6e941134 Mon Sep 17 00:00:00 2001 From: belugabehr <12578579+belugabehr@users.noreply.github.com> Date: Tue, 10 Sep 2024 10:52:38 -0400 Subject: [PATCH 2/2] Update lang/java/avro/src/main/java/org/apache/avro/util/MapUtil.java Co-authored-by: Martin Grigorov --- lang/java/avro/src/main/java/org/apache/avro/util/MapUtil.java | 1 + 1 file changed, 1 insertion(+) 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 23e4ea9c43e..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 @@ -33,6 +33,7 @@ private MapUtil() { * "https://bugs.openjdk.java.net/browse/JDK-8161372">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);