Skip to content

Commit a9a1c86

Browse files
javachefacebook-github-bot
authored andcommitted
Convert com.facebook.react.bridge.ReactSoftExceptionLogger to Kotlin (#47513)
Summary: Pull Request resolved: #47513 Changelog: [Internal] Reviewed By: tdn120 Differential Revision: D65602362 fbshipit-source-id: 95e63bd04480c1c8a364fcf93d24f71f94057d65
1 parent b60e363 commit a9a1c86

File tree

3 files changed

+72
-73
lines changed

3 files changed

+72
-73
lines changed

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,13 +1441,13 @@ public class com/facebook/react/bridge/ReactNoCrashSoftException : java/lang/Run
14411441
public fun <init> (Ljava/lang/Throwable;)V
14421442
}
14431443

1444-
public class com/facebook/react/bridge/ReactSoftExceptionLogger {
1445-
public fun <init> ()V
1446-
public static fun addListener (Lcom/facebook/react/bridge/ReactSoftExceptionLogger$ReactSoftExceptionListener;)V
1447-
public static fun clearListeners ()V
1448-
public static fun logSoftException (Ljava/lang/String;Ljava/lang/Throwable;)V
1449-
public static fun logSoftExceptionVerbose (Ljava/lang/String;Ljava/lang/Throwable;)V
1450-
public static fun removeListener (Lcom/facebook/react/bridge/ReactSoftExceptionLogger$ReactSoftExceptionListener;)V
1444+
public final class com/facebook/react/bridge/ReactSoftExceptionLogger {
1445+
public static final field INSTANCE Lcom/facebook/react/bridge/ReactSoftExceptionLogger;
1446+
public static final fun addListener (Lcom/facebook/react/bridge/ReactSoftExceptionLogger$ReactSoftExceptionListener;)V
1447+
public static final fun clearListeners ()V
1448+
public static final fun logSoftException (Ljava/lang/String;Ljava/lang/Throwable;)V
1449+
public static final fun logSoftExceptionVerbose (Ljava/lang/String;Ljava/lang/Throwable;)V
1450+
public static final fun removeListener (Lcom/facebook/react/bridge/ReactSoftExceptionLogger$ReactSoftExceptionListener;)V
14511451
}
14521452

14531453
public abstract interface class com/facebook/react/bridge/ReactSoftExceptionLogger$ReactSoftExceptionListener {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactSoftExceptionLogger.java

Lines changed: 0 additions & 66 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.react.bridge
9+
10+
import com.facebook.common.logging.FLog
11+
import com.facebook.proguard.annotations.DoNotStrip
12+
import java.util.concurrent.CopyOnWriteArrayList
13+
import kotlin.jvm.JvmStatic
14+
15+
@DoNotStrip
16+
public object ReactSoftExceptionLogger {
17+
18+
// Use a list instead of a set here because we expect the number of listeners
19+
// to be very small, and we want listeners to be called in a deterministic
20+
// order.
21+
private val listeners: MutableList<ReactSoftExceptionListener> = CopyOnWriteArrayList()
22+
23+
@JvmStatic
24+
public fun addListener(listener: ReactSoftExceptionListener): Unit {
25+
if (!listeners.contains(listener)) {
26+
listeners.add(listener)
27+
}
28+
}
29+
30+
@JvmStatic
31+
public fun removeListener(listener: ReactSoftExceptionListener): Unit {
32+
listeners.remove(listener)
33+
}
34+
35+
@JvmStatic
36+
public fun clearListeners(): Unit {
37+
listeners.clear()
38+
}
39+
40+
@JvmStatic
41+
public fun logSoftExceptionVerbose(category: String, cause: Throwable): Unit {
42+
logSoftException("${category}|${cause.javaClass.simpleName}:${cause.message}", cause)
43+
}
44+
45+
@JvmStatic
46+
public fun logSoftException(category: String, cause: Throwable): Unit {
47+
if (!listeners.isEmpty()) {
48+
for (listener in listeners) {
49+
listener.logSoftException(category, cause)
50+
}
51+
} else {
52+
FLog.e(category, "Unhandled SoftException", cause)
53+
}
54+
}
55+
56+
@JvmStatic
57+
@DoNotStrip
58+
private fun logNoThrowSoftExceptionWithMessage(category: String, message: String) {
59+
logSoftException(category, ReactNoCrashSoftException(message))
60+
}
61+
62+
public fun interface ReactSoftExceptionListener {
63+
public fun logSoftException(category: String, cause: Throwable)
64+
}
65+
}

0 commit comments

Comments
 (0)