Remove unnecessary ReactCxxErrorHandler (#54704)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/54704

This class is coming from Legacy Architecture and is no longer used so can be cleaned up.

Changelog:
[Internal] [Changed] -

Reviewed By: mdvacca

Differential Revision: D87925037

fbshipit-source-id: 30faffef0da2b7055a6d381b41dc72bead2dd8de
This commit is contained in:
Nicola Corti authored and meta-codesync[bot] committed 2025-11-27 11:17:22 -08:00
1 parent 7ba231d477
commit dba18bbc50
7 files changed
-133

No files matched your search

@@ -59,7 +59,6 @@ import com.facebook.react.bridge.JavaScriptExecutorFactory;
import com.facebook.react.bridge.NativeModuleRegistry;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactCxxErrorHandler;
import com.facebook.react.bridge.ReactMarker;
import com.facebook.react.bridge.ReactMarkerConstants;
import com.facebook.react.bridge.ReactNoCrashSoftException;
@@ -75,7 +74,6 @@ import com.facebook.react.common.SurfaceDelegateFactory;
import com.facebook.react.common.annotations.internal.LegacyArchitecture;
import com.facebook.react.common.annotations.internal.LegacyArchitectureLogLevel;
import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger;
import com.facebook.react.common.build.ReactBuildConfig;
import com.facebook.react.devsupport.DevSupportManagerFactory;
import com.facebook.react.devsupport.ReactInstanceDevHelper;
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
@@ -107,7 +105,6 @@ import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper;
import com.facebook.soloader.SoLoader;
import com.facebook.systrace.Systrace;
import com.facebook.systrace.SystraceMessage;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -304,8 +301,6 @@ public class ReactInstanceManager {
mDevSupportManager.startInspector();
}
registerCxxErrorHandlerFunc();
// Using `if (true)` just to prevent tests / lint errors.
if (true) {
// Legacy architecture of React Native is deprecated and can't be initialized anymore.
@@ -402,24 +397,6 @@ public class ReactInstanceManager {
mDevSupportManager.handleException(e);
}
private void registerCxxErrorHandlerFunc() {
if (!ReactBuildConfig.UNSTABLE_ENABLE_MINIFY_LEGACY_ARCHITECTURE) {
Class[] parameterTypes = new Class[1];
parameterTypes[0] = Exception.class;
Method handleCxxErrorFunc = null;
try {
handleCxxErrorFunc = ReactInstanceManager.class.getMethod("handleCxxError", parameterTypes);
} catch (NoSuchMethodException e) {
FLog.e("ReactInstanceHolder", "Failed to set cxx error handler function", e);
}
ReactCxxErrorHandler.setHandleErrorFunc(this, handleCxxErrorFunc);
}
}
private void unregisterCxxErrorHandlerFunc() {
ReactCxxErrorHandler.setHandleErrorFunc(null, null);
}
static void initializeSoLoaderIfNecessary(Context applicationContext) {
// Call SoLoader.initialize here, this is required for apps that does not use exopackage and
// does not use SoLoader for loading other native code except from the one used by React Native
@@ -799,7 +776,6 @@ public class ReactInstanceManager {
moveToBeforeCreateLifecycleState();
mMemoryPressureRouter.destroy(mApplicationContext);
unregisterCxxErrorHandlerFunc();
mCreateReactContextThread = null;
synchronized (mAttachedReactRoots) {
@@ -1,54 +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.bridge
import com.facebook.common.logging.FLog
import com.facebook.proguard.annotations.DoNotStrip
import com.facebook.react.common.annotations.internal.LegacyArchitecture
import com.facebook.react.common.annotations.internal.LegacyArchitectureLogLevel
import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger
import java.lang.reflect.Method
@DoNotStrip
@LegacyArchitecture
@Deprecated(
message = "This class is part of Legacy Architecture and will be removed in a future release",
level = DeprecationLevel.WARNING,
)
internal object ReactCxxErrorHandler {
init {
LegacyArchitectureLogger.assertLegacyArchitecture(
"ReactCxxErrorHandler",
LegacyArchitectureLogLevel.WARNING,
)
}
private var handleErrorFunc: Method? = null
private var handlerObject: Any? = null
@DoNotStrip
@JvmStatic
fun setHandleErrorFunc(handlerObject: Any?, handleErrorFunc: Method?) {
this.handlerObject = handlerObject
this.handleErrorFunc = handleErrorFunc
}
@DoNotStrip
@JvmStatic
// For use from within the C++ JReactCxxErrorHandler
private fun handleError(message: String) {
handleErrorFunc?.let {
try {
val parameters = arrayOf<Any>(Exception(message))
it.invoke(handlerObject, parameters)
} catch (e: Exception) {
FLog.e("ReactCxxErrorHandler", "Failed to invoke error handler function", e)
}
}
}
}
@@ -55,7 +55,6 @@ add_library(
InspectorNetworkRequestListener.cpp
JExecutor.cpp
JMessageQueueThread.cpp
JReactCxxErrorHandler.cpp
JReactSoftExceptionLogger.cpp
JRuntimeExecutor.cpp
JRuntimeScheduler.cpp
@@ -30,7 +30,6 @@
#include <logger/react_native_log.h>
#include "JReactCxxErrorHandler.h"
#include "JReactSoftExceptionLogger.h"
#include "JavaScriptExecutorHolder.h"
#include "JniJSModulesUnbundle.h"
@@ -147,7 +146,6 @@ void log(ReactNativeLogLevel level, const char* message) {
break;
case ReactNativeLogLevelError:
LOG(ERROR) << message;
JReactCxxErrorHandler::handleError(message);
break;
case ReactNativeLogLevelFatal:
LOG(FATAL) << message;
@@ -1,20 +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.
*/
#include "JReactCxxErrorHandler.h"
#include <utility>
using namespace facebook::react;
void JReactCxxErrorHandler::handleError(std::string message) {
static const auto handleError =
javaClassStatic()->getStaticMethod<void(std::string message)>(
"handleError");
return handleError(javaClassStatic(), std::move(message));
}
@@ -1,22 +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.
*/
#pragma once
#include <fbjni/fbjni.h>
#include <string>
namespace facebook::react {
class JReactCxxErrorHandler : public jni::JavaClass<JReactCxxErrorHandler> {
public:
static constexpr const char *kJavaDescriptor = "Lcom/facebook/react/bridge/ReactCxxErrorHandler;";
static void handleError(std::string message);
};
} // namespace facebook::react
-10
View File
@@ -7182,16 +7182,6 @@ class JMessageQueueThread : public MessageQueueThread {
};
} // namespace facebook::react
/// @src {packages/react-native/ReactAndroid/src/main/jni/react/jni/JReactCxxErrorHandler.h}:
namespace facebook::react {
class JReactCxxErrorHandler : public jni::JavaClass<JReactCxxErrorHandler> {
public:
static constexpr const char* kJavaDescriptor =
"Lcom/facebook/react/bridge/ReactCxxErrorHandler;";
static void handleError(std::string message);
};
} // namespace facebook::react
/// @src {packages/react-native/ReactAndroid/src/main/jni/react/jni/JReactMarker.h}:
namespace facebook::react {
class JReactMarker : public facebook::jni::JavaClass<JReactMarker> {