diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/test/FabricMountingManagerTest.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/test/FabricMountingManagerTest.cpp index 6f82841063d..cb86d39f822 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/test/FabricMountingManagerTest.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/test/FabricMountingManagerTest.cpp @@ -32,32 +32,24 @@ namespace facebook::react { * `allocatedViewsMutex_`; they never call into Java. That is what makes them * unit-testable here. * - * NOTE: `~FabricMountingManager()` calls `jni::ThreadScope::WithClassLoader`, - * which throws `std::runtime_error` when no JavaVM has been attached (see - * `xplat/spectrum/androidLibs/fbjni/cxx/fbjni/detail/Environment.h`). Because - * no JVM is available in this host-side test, the manager instance is - * intentionally never destroyed: each test allocates a single - * `FabricMountingManager` on the heap and wraps it in a `std::shared_ptr` - * with a no-op deleter. The resulting per-test leak is bounded (one ~100-byte - * instance) and does not cross test boundaries. + * `react/fabric:jni` is an Android-only native library, so this target is + * built as a JNI instrumentation test: the gtest binary is packaged into an + * APK and executed on a device/emulator. A JavaVM is therefore attached, which + * `~FabricMountingManager()` requires — it calls + * `jni::ThreadScope::WithClassLoader`, which throws `std::runtime_error` when + * fbjni has not been initialized (see + * `xplat/spectrum/androidLibs/fbjni/cxx/fbjni/detail/Environment.h`). */ class FabricMountingManagerTest : public ::testing::Test { protected: - // Returns a `FabricMountingManager` whose destructor is suppressed. - // See the class-level note above for why this is necessary. - static std::shared_ptr makeManager() { - // `jni::global_ref<>` default-constructs to an empty (null) reference, - // so no JNI calls are performed during construction. The empty - // reference is safe to copy into the manager because the - // surface-registry methods under test never dereference - // `javaUIManager_`. - auto* emptyRef = new jni::global_ref(); - auto* raw = new FabricMountingManager(*emptyRef); - // `emptyRef` is intentionally leaked: resetting it would also engage - // `WithClassLoader`, which requires an attached JavaVM. - return {raw, [](FabricMountingManager* /*unused*/) noexcept { - // No-op deleter: see class-level note. - }}; + // An empty (null) reference: `jni::global_ref<>` default-constructs to null, + // so no JNI call happens when it is created, copied into the manager, or + // released. The surface-registry methods under test never dereference + // `javaUIManager_`. + jni::global_ref emptyUIManager_; + + std::unique_ptr makeManager() { + return std::make_unique(emptyUIManager_); } }; diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/jni/test/ModuleRegistryBuilderTest.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/jni/test/ModuleRegistryBuilderTest.cpp index bd9ac941b05..7fd7f1478cd 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/jni/test/ModuleRegistryBuilderTest.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/jni/test/ModuleRegistryBuilderTest.cpp @@ -25,7 +25,7 @@ namespace facebook::react { * exercised by the Robolectric / instrumentation tests that run against a * real JVM. * - * The one branch that can be validated host-side without an attached JavaVM + * The one branch that can be validated without calling into Java at all * is `buildNativeModuleList`'s null-collection guard: when the incoming * `alias_ref>` is a null reference, the function must * short-circuit and return an empty vector rather than dereferencing the @@ -47,7 +47,7 @@ namespace facebook::react { * bring-up paths that legitimately pass no legacy Java modules). Because * the crash would only surface once the process actually reaches this * code with a null collection, catching it here — instead of relying on - * a device-side smoke test — is the earliest signal available. + * an app-level smoke test — is the earliest signal available. * * The `Instance` weak_ptr and `MessageQueueThread` shared_ptr are supplied * as empty on purpose: the guard runs before either is dereferenced, so