1313import java .util .Iterator ;
1414import java .util .List ;
1515import java .util .Map ;
16+ import org .jetbrains .annotations .NotNull ;
17+ import org .jetbrains .annotations .Nullable ;
1618import org .json .JSONArray ;
1719import org .json .JSONException ;
1820import org .json .JSONObject ;
@@ -22,8 +24,17 @@ private RNSentryJsonUtils() {
2224 throw new AssertionError ("Utility class should not be instantiated" );
2325 }
2426
25- public static JSONObject getOptionsFromConfigurationFile (
26- Context context , String fileName , ILogger logger ) {
27+ /**
28+ * Read the configuration file in the Android assets folder and return the options as a
29+ * JSONObject.
30+ *
31+ * @param context Android Context
32+ * @param fileName configuration file name
33+ * @param logger Sentry logger
34+ * @return JSONObject with the configuration options
35+ */
36+ public static @ Nullable JSONObject getOptionsFromConfigurationFile (
37+ @ NotNull Context context , @ NotNull String fileName , @ NotNull ILogger logger ) {
2738 try (InputStream inputStream = context .getAssets ().open (fileName );
2839 BufferedReader reader = new BufferedReader (new InputStreamReader (inputStream ))) {
2940
@@ -46,7 +57,7 @@ public static JSONObject getOptionsFromConfigurationFile(
4657 }
4758 }
4859
49- private static Map <String , Object > jsonObjectToMap (JSONObject jsonObject ) {
60+ private static @ NotNull Map <String , Object > jsonObjectToMap (@ NotNull JSONObject jsonObject ) {
5061 Map <String , Object > map = new HashMap <>();
5162 Iterator <String > keys = jsonObject .keys ();
5263 while (keys .hasNext ()) {
@@ -62,7 +73,7 @@ private static Map<String, Object> jsonObjectToMap(JSONObject jsonObject) {
6273 return map ;
6374 }
6475
65- private static List <Object > jsonArrayToList (JSONArray jsonArray ) {
76+ private static @ NotNull List <Object > jsonArrayToList (@ NotNull JSONArray jsonArray ) {
6677 List <Object > list = new ArrayList <>();
6778
6879 for (int i = 0 ; i < jsonArray .length (); i ++) {
@@ -73,7 +84,7 @@ private static List<Object> jsonArrayToList(JSONArray jsonArray) {
7384 return list ;
7485 }
7586
76- private static Object convertValue (Object value ) {
87+ private static @ Nullable Object convertValue (@ Nullable Object value ) {
7788 if (value instanceof JSONObject ) {
7889 return jsonObjectToMap ((JSONObject ) value );
7990 } else if (value instanceof JSONArray ) {
@@ -83,7 +94,16 @@ private static Object convertValue(Object value) {
8394 }
8495 }
8596
86- public static ReadableMap jsonObjectToReadableMap (JSONObject jsonObject ) {
97+ /**
98+ * Convert a JSONObject to a ReadableMap
99+ *
100+ * @param jsonObject JSONObject to convert
101+ * @return ReadableMap with the same data as the JSONObject
102+ */
103+ public static @ Nullable ReadableMap jsonObjectToReadableMap (@ Nullable JSONObject jsonObject ) {
104+ if (jsonObject == null ) {
105+ return null ;
106+ }
87107 Map <String , Object > map = jsonObjectToMap (jsonObject );
88108 return (WritableMap ) RNSentryMapConverter .convertToJavaWritable (map );
89109 }
0 commit comments