diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/internal/bolts/Task.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/internal/bolts/Task.kt index 7f8074f1546..0aa955ab070 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/internal/bolts/Task.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/internal/bolts/Task.kt @@ -19,28 +19,6 @@ import java.util.concurrent.TimeUnit * @param The type of the result of the task. */ public class Task : TaskInterface { - - /** - * Interface for handlers invoked when a failed `Task` is about to be finalized, but the exception - * has not been consumed. - * - * The handler will execute in the GC thread, so if the handler needs to do anything time - * consuming or complex it is a good idea to fire off a `Task` to handle the exception. - * - * @see [unobservedExceptionHandler] - */ - internal fun interface UnobservedExceptionHandler { - /** - * Method invoked when the given task has an unobserved exception. - * - * Any exception thrown by this method will be ignored. - * - * @param t the task - * @param e the exception - */ - public fun unobservedException(t: Task<*>, e: UnobservedTaskException) - } - private val lock = Object() private var complete = false private var cancelled = false @@ -48,9 +26,6 @@ public class Task : TaskInterface { private var result: TResult? = null private var error: Exception? = null - private var errorHasBeenObserved = false - - private var unobservedErrorNotifier: UnobservedErrorNotifier? = null private val continuations: MutableList> = mutableListOf() internal constructor() @@ -97,13 +72,6 @@ public class Task : TaskInterface { /** @return The error for the task, if set. `null` otherwise. */ override fun getError(): Exception? = synchronized(lock) { - if (error != null) { - this.errorHasBeenObserved = true - if (unobservedErrorNotifier != null) { - unobservedErrorNotifier!!.setObserved() - this.unobservedErrorNotifier = null - } - } return error } @@ -274,11 +242,8 @@ public class Task : TaskInterface { } this.complete = true this.error = error - this.errorHasBeenObserved = false lock.notifyAll() runContinuations() - if (!errorHasBeenObserved && unobservedExceptionHandler != null) - this.unobservedErrorNotifier = UnobservedErrorNotifier(this) return true } @@ -293,14 +258,6 @@ public class Task : TaskInterface { /** An [java.util.concurrent.Executor] that executes tasks on the UI thread. */ @JvmField public val UI_THREAD_EXECUTOR: Executor = Executors.UI_THREAD - /** - * Handler invoked when a task has an unobserved exception. Null, unless explicitly set. - * - * @param eh the object to use as an unobserved exception handler. If null then - * unobserved exceptions will be ignored. - */ - internal var unobservedExceptionHandler: UnobservedExceptionHandler? = null - @JvmStatic internal fun create(): TaskCompletionSource { return TaskCompletionSource() diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/internal/bolts/UnobservedErrorNotifier.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/internal/bolts/UnobservedErrorNotifier.kt deleted file mode 100644 index e759546a2e0..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/internal/bolts/UnobservedErrorNotifier.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.react.runtime.internal.bolts - -/** - * This class is used to retain a faulted task until either its error is observed or it is - * finalized. If it is finalized with a task, then the uncaught exception handler is executed with - * an UnobservedTaskException. - */ -internal class UnobservedErrorNotifier(private var task: Task<*>?) { - - protected fun finalize() { - task?.let { faultedTask -> - Task.unobservedExceptionHandler?.unobservedException( - faultedTask, UnobservedTaskException(faultedTask.getError())) - } - } - - fun setObserved(): Unit { - task = null - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/internal/bolts/UnobservedTaskException.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/internal/bolts/UnobservedTaskException.kt deleted file mode 100644 index 3566ba02fa9..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/internal/bolts/UnobservedTaskException.kt +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.react.runtime.internal.bolts - -/** Used to signify that a Task's error went unobserved. */ -internal class UnobservedTaskException(cause: Throwable?) : RuntimeException(cause) {}