From c0b488305860fabd3d737674d614e4f466ace0ed Mon Sep 17 00:00:00 2001 From: David Vacca Date: Tue, 4 Apr 2023 10:43:56 -0700 Subject: [PATCH] Deprecate and mark for removal com.facebook.react.common.StandardCharsets (#36779) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36779 Deprecate and mark for removal com.facebook.react.common.StandardCharsets, this class was originally created because java.nio.charset.StandardCharsets only exists in Android API level 19+ As part of this diff I also migrate all internal usages of com.facebook.react.common.StandardCharsets Changelog: [Android][Deprecated] - Deprecate and mark for removal com.facebook.react.common.StandardCharsets, please use java.nio.charset.StandardCharsets instead Reviewed By: rshest Differential Revision: D44592721 fbshipit-source-id: c3f4286766209a733b466d19dc36891f12d69be1 --- .../main/java/com/facebook/react/common/ArrayUtils.java | 3 ++- .../java/com/facebook/react/common/StandardCharsets.java | 7 ++++++- .../facebook/react/modules/network/NetworkingModule.java | 2 +- .../react/modules/network/NetworkingModuleTest.java | 2 +- .../modules/network/ProgressiveStringDecoderTest.java | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/ArrayUtils.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/ArrayUtils.java index 4ff50c54a9daf4..def6056917fb01 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/ArrayUtils.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/ArrayUtils.java @@ -9,10 +9,11 @@ import java.util.Arrays; import java.util.List; +import javax.annotation.Nullable; public class ArrayUtils { - public static float[] copyArray(float[] array) { + public static float[] copyArray(@Nullable float[] array) { return array == null ? null : Arrays.copyOf(array, array.length); } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/StandardCharsets.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/StandardCharsets.java index 9399888a16c5a1..4c886ef03832c6 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/StandardCharsets.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/StandardCharsets.java @@ -13,7 +13,12 @@ * Not all versions of Android SDK have this class in nio package. This is the reason to have it * around. */ -public class StandardCharsets { +@Deprecated( + since = "Deprecated class since v0.73.0, please use java.nio.charset.StandardCharsets instead.", + forRemoval = true) +public final class StandardCharsets { + + private StandardCharsets() {} /** Eight-bit UCS Transformation Format */ public static final Charset UTF_8 = Charset.forName("UTF-8"); diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java index 1c4b373f126aa1..020f8b82e277fb 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java @@ -20,12 +20,12 @@ import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.WritableMap; -import com.facebook.react.common.StandardCharsets; import com.facebook.react.common.network.OkHttpCallUtil; import com.facebook.react.module.annotations.ReactModule; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashSet; import java.util.List; diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/modules/network/NetworkingModuleTest.java b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/modules/network/NetworkingModuleTest.java index a49e6ebc2c857a..6483953b104fe0 100644 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/modules/network/NetworkingModuleTest.java +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/modules/network/NetworkingModuleTest.java @@ -23,9 +23,9 @@ import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.WritableArray; import com.facebook.react.bridge.WritableMap; -import com.facebook.react.common.StandardCharsets; import com.facebook.react.common.network.OkHttpCallUtil; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; import okhttp3.Call; diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/modules/network/ProgressiveStringDecoderTest.java b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/modules/network/ProgressiveStringDecoderTest.java index a714df574b6310..3078bcbfa64942 100644 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/modules/network/ProgressiveStringDecoderTest.java +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/modules/network/ProgressiveStringDecoderTest.java @@ -7,8 +7,8 @@ package com.facebook.react.modules.network; -import com.facebook.react.common.StandardCharsets; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith;